| |
VI and the Shell
Due: Monday January 25, 1999
Hand in your output during class on Monday. (I expect you to complete most of the
lab during Thursday and Friday.)
Purpose:
| Practice the VI text editor. |
| Review understanding of the Unix shell. |
| Write a cool shell script. |
Assignment:
- Answer and hand in these review exercises in Chapter 10 (Bourne Shell):
1, 2, 3, 5, 7, 13
- Login to the desktop on a Unix machine in either Lab. Get a window with a shell
prompt in it. Generate a list of all the processes that are parents and ancestors of
that shell, right back to process number one. Hand in your list.
- Telnet to another Unix machine. Log in. Repeat the previous question for
your telnet session.
- Chapter 8 (VI): Answer and hand in review exercises 1, 2, 3, 4, 5, 6,
7, 8, 10
- Scripting: The comm command prints the lines common to
a pair of sorted files, as well as the lines that appear only in the first file and the
lines that appear only in the second file. (Read the man page for how to suppress
unwanted lines in the output.) Use this command, and any other commands you might
need, to write a shell script that generates a list of Solaris command names that are
common to both the /usr/bin directory and the /usr/ucb
directory. (The list will be only file names that appear in both
directories on Solaris.) Hand in your completed script and only the first ten and
last ten lines of the list of common files that are the output from your script, plus a
count of the total number of file names generated by your script. (Do not hand in
the whole output list generated by your script!) Hint: Your script
will have to generate two temporary lists of file names first.
- Bonus: Have your script (from the previous question) compare any
two directories given as arguments to the script. If exactly two arguments
are not given, print a helpful error message and exit without doing anything. (See the
explanation of the $# variable on p.297 and a sample of its use on
p.303.) The text of your error message must appear on standard error, not on
standard output. (See p.281-283 and the script on the bottom of page 303.)
- Bonus Bonus: Instead of an error message, have your script (from the
previous question) prompt the user to enter either or both of the script arguments if they
are missing. (See the read command on p.290-291.)
Note: There are two echo command styles, one for
System V Unix systems, and one for Berkeley Unix systems. (Read the man pages on
Linux and Solaris to see the differences!) The book uses the System V style, where '\c'
at the end of a line suppresses the newline. This works on Solaris. To get the
same effect under Linux, which is Berkeley-based, don't use '\c' but
instead give a '-n' option to echo:
$ echo 'No newline at end of this line\c'
No newline at end of this line$
$ PATH=/usr/ucb:$PATH ; export PATH
$ echo 'Ooops now we are using Berkeley echo\c'
Ooops now we are using Berkeley echo\c
$ echo -n 'This is how you suppress a newline now'
This is how you suppress a newline now$
You may find the above useful for generating prompts for input. If your shell
script puts /usr/ucb first in the PATH for the script, you can use the
Berkeley syntax on both Linux and Solaris.
Hand in:
Hand in, on paper, the answers to the above questions.
Additional material:
|