Due Date

Due: Tuesday, January 21, 2014 at 11 PM.

Objectives

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

References

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.

Also, look at man pages and other descriptions of commands. Sometimes options are available that allow a single command to do something you want instead of having to use several commands.

Assignment

  1. (Commands and output) Use each of the following commands such that fleem (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, run other commands, etc.) and/or pass options or arguments to your commands. Solve this problem for each of the commands listed below individually.
    echo, cat, ls, grep, !!
    In a text file called problem1 describe your solutions, including each command you use and a very brief explanation of it. And, yes, "nothing more" in the output means "nothing more".

  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 current 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 either /dev/stdout or /dev/stderr. These are not portable across *nix systems. Although they are found on most versions of Linux, 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.

    More hints: shift, $@, -lt, -a.

    About hints: 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:
    	  Wed Jan 15 20:42:16 PDT 2014
    	  4 foo
    	  17 bar
    	  21 total
    	  Wed Jan 15 20:42:17 PDT 2014
    	  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. (See extra credit policy in the syllabus.)

Assessment

Your solutions should be

Identifying information including

should appear as comments at the top of each of your files.

Turn-in Instructions

Use the turn-in drop box link on the main course web page to submit your files:
  1. problem1
  2. defprivate
  3. combine
  4. datedlinecount

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.

(The drop box will allow you to turn in your homework up to two days late, if you choose to use one or two of your late days, but you are strongly advised to save your late days for later in the quarter when they may be much more useful.)