-------------------------------- DAT2330 - Unix - 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 5 - The Shell. Omit material that uses the line printer commands, e.g. "lpr". - True or False: These two command lines are equivalent: $ ls -l -i -d $ ls -lid - True or False: Every Unix command that takes several option letters lets you group them into a single argument starting with one hyphen. - When processing a shell command line, which software handles the ^U (CONTROL-U) line kill function? - the shell or the operating system terminal driver - the application program (e.g. "cat" or "sort") on the command line - In terms of parsing the command line, what is a "word" or "token"? - How does the shell differ in its treatment of command names that contain slashes vs. command names without slashes? Explain the differences: $ ls $ /bin/ls $ who $ /usr/bin/who - True or False: To find commands to run, the shell always looks in every system directory on the machine. - True or False: You cannot change the places where the SHELL looks to find commands; the locations are built into the Unix system. - Will the "echo" command still work if you set your PATH variable to be empty? $ PATH='' $ echo "Does this work?" Explain the results. Now try "ls" and "date". Now try "/bin/ls" and "/bin/date". Your shell won't work very well now, with PATH set to be empty. How can you get a fresh shell with a correct default PATH? - True or False: The shell issues error messages about unrecognized options to commands, e.g. "who -z". - True or False: To the shell, a command is simply an executable file of the same name as the command name. - True or False: Standard input of every command on a command line is always your keyboard. Standard output is always your terminal screen. - Find the Unix pathname of the terminal with which you are connected to Unix (text p.95). Echo something and redirect the output into this pathname. Where does the output appear? Copy a short file onto this pathname using the "cp" command. Where does the output appear? $ cp /etc/group /dev/pts/4 - Study the differences between text figures 5-3, 5-5, and 5-8. Is it possible to redirect both the standard input *AND* the standard output of a Unix command at the same time? Give an example, if this is possible. - Go to the web site for the author and this textbook and find the correction to be applied to Figure 5-9. (The web site is mentioned in the intoductory pages.) - Study the box on page 99 and understand what the shell is doing when you redirect output! - What does "noclobber" mean? - What prompt does the shell use to remind you that you are operating as the Super User on a Unix system? (You can safely become the super-user on your Floppix system - see the "superuser" Lab on www.floppix.com.) - On page 101 the text says that a pipe is identical to redirecting the output of one command into a file, then running a second command and feeding it the file as standard input. While this is a true statement for pipes used in DOS, it isn't true under Unix. Unix pipes start passing data before the first command has finished; unlike DOS, you don't have to generate the full output of the first command before any output starts appearing on the input of the second command. Unix starts passing output as soon as it is available: $ cat -n -u | tr a-z A-Z abcd 1 ABCD hello 2 HELLO ^D $ Note how each line passes all the way through the pipe as it is typed. (What do the two options to "cat" mean on ACADAIX?) - What does it mean to use a command as a "filter"? Can any Unix command be used as a filter? - What happens if you give the pathname to your terminal as the file name argument to the Unix "tee" command? Why does this happen? $ tty /dev/pts/34 $ echo "Testing testing" | tee /dev/pts/34 Explain the output. - To put a sequence of shell commands into the background, enclose the sequence in parentheses before appending the ampersand: bash$ ( sleep 5 ; date ) & [1] 50070 bash$ ( sleep 5 ; echo "Hello there" | write abcd0005 ) & [2] 50085 - Understand the use of these wildcard (glob) characters: * ? [] - What is the difference in output of these two commands? $ echo */. $ echo ./* - True or False: If a Bourne-style shell pathname expansion (globbing, or wildcard matching) fails to match any files, the expansion is passed unchanged as an argument to the underlying command: $ mkdir empty $ cd empty $ echo * [...what output do you see here...] $ touch b $ echo a* b* [...what output do you see here...] - True or False: The shell does pathname expansion before calling the utility (command) in a command line. The utility sees the *result* of the expansion, not the wildcard (glob) characters that generated it. $ touch a b c d $ echo * - True or False: the echo command receives one argument "*" and expands it to be the strings "a" "b" "c" "d" and echoes them on the screen - What is the difference in output of these two "tr" commands? (Study how the shell expands pathnames in these command lines!) $ rm -rf empty $ mkdir empty $ cd empty $ touch a b c A B C $ ls A B C a b c $ head /etc/passwd | tr [a-z] [A-Z] [...what output do you see here...] $ head /etc/passwd | tr "[a-z]" "[A-Z]" [...what output do you see here...] Why is the output different? What is happening? Chapter non-Advanced Review Questions: On ACADAIX or Linux: 1 - 9 (all) Chapter Advanced Review Questions: On ACADAIX or Linux: 10, 11, 12, 13, 14, 15, 16 Unix commands studied (summary p.111): tty, tr, tee, bg, fg, jobs