---------------------------------------------- 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 11 - Shell Programming (excerpts) Note: For much of the material, the Korn Shell, Bourne Shell, and Bash Shell behave identically. Note: Concentrate on the text sections related to material covered in lectures, assignments, and in these questions. We studied: - if/then - if/then/else - here documents - The text puts the "then" keyword on a separate line. If you put it on the same line as the "if" keyword, what must precede it? - True or False: the "command" in an "if" statement must be a shell built-in command. - True or False: the "command" in an "if" statement cannot be a pipe line or contain any redirection. - What is the usual output (on the screen) of the "test" command? - Look under "Shell variables" in the index for the explanation of the "$#" variable. What does it contain? - You should double-quote all shell variables. The $# variable is an exception - it doesn't really need to be quoted. Why? - Why should a script first check to see if a user has supplied all the required arguments (positional parameters) to the script? - What is the difference in return status (exit status) between the commands: $ test 0 = 00 $ test 0 -eq 00 - What happens if you compare strings using -eq in the "test" command? $ test abc -eq def - Note the syntax difference between versions of the "test": if test A = B ; then ... fi if [ A = B ]; then ... fi The behavviour of the above commands is identical; the second one just looks a bit neater. REMEMBER: that the brackets need to be seen as separate arguments! Use blanks! "testA = B" is as wrong as "[A = B]". Neither one works. - Enter and modify the "out" program on p.374. - add the name of the script (parameter zero) to all error messages - change "less" to "more" Note: We have not covered the "shift" command. You don't need to know how it works to make the script work. - Chapter 11 Chapter Review questions: none