CTS 1106 (Intro to Unix/Linux) Project #6
Write a Lookup Shell Script


Due: by the start of class on the date shown on the syllabus


  1. Using vi, create a ".addr_book" data file in your home directory with the appropriate permissions (so that only the owner can modify or view the file, group members can view it, and others have no access).  This file is an address book and should contain entries for people, businesses, etc.  For example you might have an entry for me: Wayne Pollock Unix/Linux Instructor Phone: 253-7213, Room T-404 Note that each entry is a single line!  Have at least 3 entries in the file.  (Don't have any blank lines or any comment lines.)
  2. If you don't already have one, create a "bin" directory within your home directory, with appropriate permissions so you have access to all files within, and group members have read-only access to all files within.  (Be careful setting these directory permissions!)
  3. If your "bin" directory isn't already part of PATH, edit your login script file so that your new bin directory appears somewhere in your PATH.  (You will have to login again for the new PATH to take effect.)  (NOTE!!  I've done this step for you already; just verify your PATH setting is correct using the commands you have learned.)
  4. Using vi, create a file called "lookup" (a shell script) in your bin directory with appropriate permissions (so you can view or modify or execute your script, group members can view or execute your script, and others have no access).  When run, lookup should find matching entries (lines) from your "$HOME/.addr_book" file and display them.  For example: lookup Pollock should display any line (record) that contains the string "Pollock".  The output MUST be sorted.  (HINT: use grep, sort, and positional parameters.  Do NOT use "read"!)


Remember it is far easier to solve this project at the command line, and only afterwards put the commands into a file "lookup".  You can try to search for some specific name in your $HOME/.addr_book file at the command line, say "Wayne".  When you got the search right, add the command to sort the result.  When that is working, your are nearly done!  Just put that command line in your ~/bin/lookup file, add a comment or two, make that file executable, and try it out.  The result should be exactly the same as when you ran the command from the command line.  Finally change Wayne to a positional parameter so your lookup command will find other people too.  That's it!  Add creative extras if you wish.

For full credit your script must include most of the features discussed in class for a shell script including: setting the script as a bash shell script, using appropriate comments, making sure lookup can find the current user's address book file regardless of the current working directory, making sure lookup will do something sensible1 even if the user fails to type any arguments to lookup, or types in multiple arguments (such as "lookup Wayne Pollock").

To be turned in:

There is nothing to turn in.  You don't need to email your files to me, or do anything else to hand them in.  On the due date I will go into your home directory and collect what I need, using my group access to read and grade your work.  Be sure all files have the exact names specified here, and be sure to complete the project by the due date.

Send project questions to .  Please use the subject "Intro to Unix/Linux Project #6 Questions" so I can tell which emails are questions about the project (and not submissions).

Refer to the Projects and the Submitting Assignments sections of your syllabus for more information.



  1. By something sensible I mean your script shouldn't hang (just sit there until the user hits control-C) and shouldn't crash with an error message from some command you used in your script.  (You can use echo to display your own messages however.)  And if the user types "lookup Joe Smith", it isn't sensible to search for all entries with "Joe", then search for all entries containing "Smith".  Back