![]() |
CS1101: Laboratory 5Shell Scripts: Control StructuresAcademic 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 Andersen'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 1st of December (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.
ls
: myls
This exercise requires a for-loop and if-statements.
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 directory.
You are required to write a shell script called myls
which has
the following specification:
myls
- list the contents of a directory labelling
elements as either files or directories.
myls
myls
:
sh
ls
to get the list
of files/directories)
test
on each file to distinguish
between files and directories.
An example of the required output is given below.
Example:
bash> ls cs1101 mail myletter bash> myls cs1101 (directory) mail (directory) myletter (file) bash>
del
This exercise requires if-statements.
The rm
command can be dangerous - you use it to delete files
without being prompted.
You also do not get any feedback.
You are required to write a shell script called del
which has
the following specification:
del
- delete files interactively.
del <filename>
del
:
sh
test -e $file
to test for the existance of a file
stored in $file
.
Submit both of your scripts using the following commands:
cs1101submit myls cs1101submit delYou're all done!
Return to the CS1101 Home Page