---------------------------------------------- DAT2330 - Unix - Winter 2000 - Prof. Ian Allen ---------------------------------------------- Here are questions you should be able to answer. You will likely find questions similar to these on tests and exams. Chapter 10 - The Bourne Again Shell (excerpts) Note: For much of the material, the Korn Shell, Bourne Shell, and Bash Shell behave identically. Note: Type in all the scripts and command lines! You can't practice debugging the scripts simply by reading them. Note: Concentrate on the text sections related to material covered in lectures, assignments, and in these questions: - Omit the section on redirecting standard error - Omit the section on job control - In the section on processes, concentrate on the subsections "Executing a Command" and "Invoking a Shell Script". - Omit the section on history - Omit the section on aliases - Omit the section on command-line editing - Which successful shell has been used in all versions of Unix and in Linux? - What is a shell script? - True or False: Shell scripts cannot have their input or output redirected. - What permissions are needed for a shell read a file containing a shell script? - What permissions are needed for Unix to execute a shell script? - What is the difference between: chmod +x file chmod u+x file - What does the semicolon special character mean to the shell? - True or False: If the command to the left of a semicolon fails (with a bad return status, or "not found"), the shell will not execute the command to the right of the semicolon. - What does the semicolon special character mean to the shell? - Give an example of a command that is built-in to the shell. - If the first line of an executable file is "#!/bin/cat", what will the output be when you execute the file? - If the first line of an executable file is "#!bin/nosuch", what will the output be when you execute the file? - What is a "positional parameter"? - What command is most often used to display the values of variables? - Fix the syntax of the following assignment: $ myvar=Hello World! - How would you append the string " dog" to the (unknown) contents of an existing variable named "foo"? For example: $ foo=my $ [your appending shell command goes here] $ echo "$foo" my dog - Why is it critical to put double quotes around variables when you use them? - When would you "export" a variable? - Can a child process change the value of a variable in its parent process? - What is contained in these shell environment variables? HOME PATH MAIL PS1 - What is the name of the positional parameter that contains the name of the shell script being run? - Study well the short section on "Command-line arguments" (p.333) - What is "Exit Status"? (See the index.) - What shell variable contains the exit status of the most recently executed command? - The order in which the shell processes each command line is given on page 358. Know in which order the processing is done for the three features we have studied: 1. Tilde, parameter, variable expansion 2. Word splitting (at blanks, semicolons, pipes, etc.) 3. Pathname expansion (wildcards) Note that pathname expansion happens last, so that wildcard characters hidden inside parameters and variables can be expanded (often unintentionally). Also note that if a wildcard matches a filename with a blank, the blank is not treated as a special character because word splitting happens *before* wildcarding. (A wildcarded filename containing one or more blanks is still treated as a single argument by the shell, because the shell already did the word splitting.) Note: The text says parameter expansion happens *before* variable expansion; this is wrong. They happen at the same time. (You can't have a parameter that expands to contain a variable and then have the variable also expand.) - Chapter 10 Chapter Review questions: 1(a),2,3,4,6,10