Recall that the command "wc" (for "word count") counts
the number of lines, words, and characters in a file, as shown in this
example from doberman, run in /etc:
sedwards@doberman%/etc
% wc shells
10 10 111 shells
If you look at the manual page for wc you will see that
it also supports the command line options -l,
-w, and -c, which indicate that it should
only report the number of lines, number of words, or number of
characters, rather than all three. If more than one such option is
given, only the counts requested are displayed:
sedwards@doberman%/etc
% wc -l -c shells
10 111 shells
Your assignment is to write a simple ksh shell script
called dir-wc, which behaves like wc
except that it
counts the number of files, lines, words, and characters in all files
in one or more directories that are provided as command line arguments.
Directories are not included in the file count, nor are files in
subdirectories included in the counts. However, dot files (other than
directories) are to be counted.
The previous assignment involved a shell script that counted the
number of files in one directory---the task here is similar,
except that more than one directory may be involved, and
the action to take for each file is different.
You are welcome to use the previous assignment or a
ksh script you have been
working on in lab as a starting point (as long as you wrote
it, perhaps together with your lab partner---you cannot borrow someone
else's).
If dir-wc is invoked with no directory name
provided, it should work on the current directory. Otherwise, it
should produce a single line of output for each directory it
processes, as in this sample (on fictitious locations):
% dir-wc
.: 10 files 491 lines 1236 words 20375 characters
% dir-wc project1 cs1206
project1: 2 files 285 lines 807 words 4212 characters
cs1206: 8 files 2017 lines 8576 words 51001 characters
Your script should also support the following command line options,
patterned after wc:
-f
-l
-w
-c
Within your script, you can use wc to calculate the totals for a single file. Be careful to exclude subdirectory names (and files in subdirectories) from all of your counts. As in the previous assignment, your script should start with the proper bang line and include normal and error return statements. Also, be sure to use comments in your script to explain what you are doing and how the main statements in your script are supposed to work.
For comparison, here is the output of a sample
dir-wc script run on chestnut:
29 Chestnut> dir-wc ~ltw ~ltw/bin /usr/share/zoneinfo /home/faculty/ltw: 5 files 112 lines 351 words 3635 characters /home/faculty/ltw/bin: 2 files 53 lines 216 words 1451 characters /usr/share/zoneinfo: 14 files 391 lines 1945 words 24443 charactersYou can use this output to test the numbers produced by your own script. Your shell script will be graded on a DEC Alpha running Digital UNIX, so you should write your script such that it runs correctly under both FreeBSD and Digital UNIX. You can test your script on any of the DEC Alphas (doberman, malamute, rottweiler, boxer, husky) in the lab. Note also that for obvious security reasons, your script will be graded within a restricted shell (
rksh), where certain operations are forbidden. Thus your
script must run under FreeBSD, Digital UNIX, and
rksh.
You are to hand in your assignment by using the Automated Grader application. To receive credit, your assignment must be submitted before the time and date listed above. It is your responsibility to successfully submit your assignment via the Automated Grader. A maximum of four submissions are allowed per student. Your submission must be a plain ASCII text file in exactly the format defined below. Do not insert any extra notes or explanations.
Your submission must be plain ASCII text that contains the following:
dir-wc shell script.
Brief instructions are given below on how to use the Grader, but it will be helpful to visit the Automated Grader's web page.
After connecting to the Internet, run the Grader program with the command:
Acceptor_UI
A dialog box will then appear. If the title of the dialog box says "CS 1206 Grader Client" then you have the correct application; otherwise you are running the wrong client application on your local machine. Fill in your original PID, e-mail password, and Student ID. Click inside the Course Index field and select the lab section you are enrolled in. Type in HW7 for the Project Number. Enter the full path of the file to be submitted, or click on Browse to find it. After all the information is typed in, click on Submit. If your submission was successful, a window will appear stating "Your file has been submitted. A confirmation will be sent to you via e-mail." If your submission did not succeed, then a dialog box will appear describing the problem. Correct the information and resubmit. If the submission was successful, click the Quit button. After a few minutes (or sometimes hours!), you should receive an e-mail message verifying the file was received.
Also, remember that no late assignments are accepted.