|
CS1101: Laboratory 4(b)More Introductory Shell ScriptingAcademic Year 2006-2007Lecturer: Dr. Barry O'SullivanDepartment of Computer Science University College Cork |
To familiarise students with the concepts of shell scripts.
This lab is based on material from Paul Anderson's book entitled "Just Enough UNIX".
During this lab you will be asked to write 2 shell scripts of your own. These must be submitted by 5pm Friday the 24st of November (this coming Friday).
All shell scripts that you write, for this course, should be based on the
sh shell.
A reference on this shell is
available online.
You should write and submit shell-scripts that meet the following specifications.
wc: mywc
The wc ("word count") filter counts the words, lines and
characters in a file.
For example. try running wc on the chex script
you created in the last lab:
bash> wc chex 5 17 84 chex bash>
The output tells us that there are 5 lines, 17 words and 84 characters in
the file chex.
You are required to write a shell script called mywc which has
the following specification:
mywc - labelled word count.
mywc <filename>
mywc:
sh
wc on $1 and capture the output using with
set
Example:
bash> mywc chex File: chex Lines: 5 Words: 17 Characters: 84
whatisit
The test command can be used to distinguish between files
and directories.
For example, test -f filename is true if filename
is a file, while test -f filename is true if
filename is a file.
You can use test -d filename to determine whether it is a directory.
You are required to write a shell script called whatisit which has
the following specification:
whatisit - distinguish between files and
directories.
whatisit <filename>
whatisit:
sh
test on $1 to distinguish between
files and directories.
The filename given is printed along with a statement of whether
it is a file or a directory.
An example is given below.
Example:
bash> whatisit chex chex is a file bash> whatisit cs1101 cs1101 is a directory bash>
Hint: Use an if-statement to first test for a file, then a
directory, otherwise assume the file or directory doesn't exist.
Submit both of your scripts using the following commands:
cs1101submit mywc cs1101submit whatisitYou're all done!
Return to the CS1101 Home Page