COP 3344-01 Introduction to Unix: Lecture 6
Learning objectives
After this class, you should be able to:
- Write shell scripts that use the Bourne shell, and run them. In particular, you should be able to use the following features: (i)
case
, (ii)exit
, (iii)for
, (iv)if
, and (v)while
.
Reading assignment
- JEA: Chapters 33.11-33.16, 33.18, Single Unix Specification for definitions of the commands.
- Lecture slides: Lecture 6.
Exercises and review questions
- Questions on current lecture's material
- The shell script
myrm3
requires one argument. Add a few statements to the beginning of this script so that it outputs an error message and the correct usage tostderr
, if the user does not supply exactly one command line argument.- The shell script
backup
expects at least one argument. Add a few statements to the beginning of this script so that it outputs an error message and the correct usage tostderr
, if the user does not supply exactly at least one command line argument.- Write a shell script called
firstword
which is run as follows:./firstword filename word1 word2
. It outputs the line number of all lines in the filefilename
which start with eitherword1
orword2
. Each line of the output has the following format:Line # <n> starts with <word>
, where<n>
is the line number and<word>
is eitherword1
orword2
. Use thecase
statement in this shell script. Do not use thegrep
utility.- Questions on next lecture's material
- None.