CS1101: Laboratory 4(b)

More Introductory Shell Scripting

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 Anderson'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 24st of November (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.

Labelling the Output from 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:

Example:

bash> mywc chex
File: chex
Lines: 5
Words: 17
Characters: 84

Is it a file or a directory: 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:

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.

Submission

Submit both of your scripts using the following commands:

cs1101submit mywc
cs1101submit whatisit
You're all done!


b.osullivan@cs.ucc.ie

Return to the CS1101 Home Page