CS1101: Laboratory 5

Shell Scripts: Control Structures

Academic Year 2006-2007

Lecturer: Dr. Barry O'Sullivan
Department of Computer Science
University College Cork

b.osullivan@cs.ucc.ie


Objective of this Lab

To familiarise students with the concepts of shell scripts.

This lab is based on material from Paul Andersen's book entitled "Just Enough UNIX".


Submission

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).


Background

All shell scripts that you write, for this course, should be based on the sh shell. A reference on this shell is available online.


Tasks

You should write and submit shell-scripts that meet the following specifications.

A customised 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:

Example:

bash> ls
cs1101 mail myletter 
bash> myls
cs1101 (directory)
mail (directory)
myletter (file)
bash>

Removing Files Safely: 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:

Submission

Submit both of your scripts using the following commands:

cs1101submit myls
cs1101submit del
You're all done!


b.osullivan@cs.ucc.ie

Return to the CS1101 Home Page