CS246 Winter 2010 Assignment 1.  TENTATIVE as of 7 Jan 2010 (4:40pm typos fixed)

http://plg.uwaterloo.ca/~holt/cs/246/2010/asgn01/asgn01.htm

Instructions to submit assignments:
http://www.student.cs.uwaterloo.ca/~isg/coursework/submit/submit

 

All the shell scripts you write should work on the bash shell.

 

Asgn 1a: A printing command pt. Write a shell script called pt (for print) that will output the contents of ASCII files.  Your script should call the cat command to do the printing.  Do not use “alias”.  Your script should be able to handle any number of files, e.g.

            pt  file1.c readme.txt

Make your script executable using the chmod command.  Test you script by typing

            ./pt  file1 file2 file3    # Where fileN is an ASCII file you created

Put your pt script into your bin directory (into ~/bin).  Check to make sure that pt can be invoked from various directories.  Trying typing

            which pt

to see where pt is located.  In all cases, including the case of no arguments, you pt command should give the same results as the cat command.  You are to submit your pt script.

 

Asgn 1b: Show hidden files showhid. Write a shell script called showhid (show hidden files) that does a long form of ls (use ls –l) of hidden files (or directories) in the current directory that contain a specific string (or pattern).  For example,

     showhid rc

should give a long listing for each hidden file  that contains the substring rc in its file name.  You can assume that the argument (rc in this example) is at least one character long and does not start with dots. As a result, you will not list the . and .. directories.  Make your command executable and put it in your bin directory. Try out your “showhid” command in your home directory to list hidden files containing the string rc.  In the case of no arguments to showhid, print out a useage message of the form:

     Usage: ./showhid [ arg ]+

You are to submit your showhid script.

Clarification (15 Jan 2010):  You should list every (hidden) file fhat matches at least one pattern.  Suppose there are multiple arguments (giving patterns) to showid.  If more than one pattern matches a given file name, then it is OK to list that file more than once.  For example, suppose there is a file called .hidden, then the following is acceptable:

$ showhid h dd file
...  .hiddenfile
...  .hiddenfile
...  .hiddenfile

 

Asgn 1c: Backup script bkup.  Write a shell script (for bash) called bkup that backs up ordinary files (not directories) with given suffixes.  For example, the command

     bkup .cc .h

will make copies of any ordinary files in the current directory (and its recursive descendent directories); if a file is called  X.cc, your script will create a copy of this file in X.cc.bkup  If no arguments are given, your script should print out a  usage-message.

 HINTS: You can use Buhr’s cleanup shell script  in his slide 45 as a model.  Familiarize yourself with the find command (type “man find” in Unix) and its –type and –name arguments.  You can use the find  command to determine ordinary files (files of type f) that match a given pattern (the existing file name ending with one of the specified suffixes).  You can practice by manually giving example “find” commands that you type into Unix, to make sure you understand what find does.

Make a small directory tree with example files, with various suffixes, that you can use to demonstrate to yourself that your bkup command is working correctly.   Try turning on the trace facility with the –x flag in the first line of your bkup script.  Remove the –x before submitting your solution script.  During testing, you probably want to temporarily add your own tracing statements using “echo”.

 

You are to submit your bkup script.