![]() |
CS1101: Laboratory 6(b)A useful shell script -
|
To familiarise students with the concepts of shell scripts.
This lab is based on material from Paul Andersen's book entitled "Just Enough UNIX".
During this lab you will be asked to write 1 shell script of your own. It must be submitted by 5pm Friday the 8th of December (Friday of this week).
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 a shell-script that meets the following specification.
You are required to write a shell script called usage
which has
the following specification:
usage
- reports the size of the
file passed as an argument, or lists the contents of the a directory with the
sizes of each entry.
usage
usage
:
du-sk
command can be used to report the size of a file
du -sk
- read the manual page for du
to get
information on this command.
test -f
, while
test -d
can be used to identify a directory.
Use will need if
and for
statements here.
Example:
bash> usage Mail Mail is a directory It's total size is 100kb Contents: cs1101 (file) 10kb friends (file) 100kb backup (directory) 110kb bash> bash> usage usage usage is a file It's size is 4kb bash>
Submit your script using the following command:
cs1101submit usageYou're all done!
Return to the CS1101 Home Page