CSE logo University of Washington Computer Science & Engineering
 CSE 374 Programming Concepts and Tools - Homework 2 - Spring 2009
  CSE Home   About Us    Search    Contact Info 

Due: Thursday, April 9, at 11 pm.

In this assignment you'll gain some more experience with shell commands and with writing short shell scripts.

General hint: Before trying to write and debug a script , it's very helpful to first work out the necessary commands by experimenting in a shell window.

  1. (Commands and output) Use each of the following commands such that xyzzy (and nothing more) is printed on standard out, and nothing is printed on standard error when the command is entered. You can precede your commands with other commands (e.g., to create a file) and/or pass options to your commands. Solve this problem for each of the listed commands individually.
        echo, cat, ls, grep, !!
        
    Hint: The last one can be tricky. Think about various ways to define commands, aliases, or shell scripts.

    In a text file called problem1 describe your solution, including each command you use and a very brief explanation of it.

  2. (An alias) Create a bash alias private such that when you run private foo, the entire subtree of the file-system starting at foo (so just foo if it is a file, but foo and all of its files and subdirectories recursively if it is a directory) has its permissions changed as follows:
    Put your alias in a file defprivate such that entering source defprivate would make private available in the shell.

  3. (Script) Create a bash script combine that takes 2 or more arguments, call them f1, f2, ..., fn. Script combine should work as follows:

    Restriction: You may not use /dev/stdout and/or /dev/stderr. These are not portable across *nix systems, although they are found on most versions of Linux, and the problem can be solved without them.

    Hint: Put filenames in double-quotes in case they contain "funny characters" (such as spaces). Your script should work with any file names, no matter what they contain.

    Hints: shift, $@, -lt, -a.

    Hint: Hints are just ideas you might find useful, not things that must appear in your solution.

  4. (Script) Create a bash script called datedlinecount that works as follows:


    For example, executing: ./datedlinecount log foo bar; ./datedlinecount log foo*; cat log might produce something like:
    	  Mon Mar 26 20:42:16 PDT 2009
    	  4 foo
    	  17 bar
    	  21 total
    	  Mon Mar 26 20:42:17 PDT 2009
    	  4 foo
    	  3 food
    	  7 total
    
    Hints: shift, date, wc, $@.

    Extra credit: The output should include a total line even if only a single file appears in the list.

Assessment: Your solutions should be

Identifying information including your name, CSE 374 Homework 2, the problem number, and the date should appear as comments in each of your files.


Turn-in Instructions: Use the turn-in drop box link on the main course web page to submit your files. If you wish, you can combine your files into an archive (see the tar command) and turn that in as a single file. The choice is yours; do whichever is most convenient.


CSE logo Computer Science & Engineering
University of Washington
Box 352350
Seattle, WA  98195-2350
(206) 543-1695 voice, (206) 543-2969 FAX
[comments to Hal Perkins]