Homework 2

  1. Commands are found in various directories as given by the environment variable PATH. View this by typeing echo $PATH. The various directories are separated by colons (:), and they are difficult to see. Write a sed command line to break the components of your path into separate lines, and print them out that way.

    Hint: \n, back-slash-n, is the symbol of making a new line. Get your path into sed input by piping echo.

  2. Write a shell script called whichpath which takes a match string and looks in your $PATH variable for paths containing the match string. It prints out each path which matches.

    Hint: use the previous exercise and add another element to the end of the pipe. In a script $1 is expanded to the first argument on the command line that ran the script.

    Here is an example:
    
         [csc322@lee ~/bin]$ whichpath java
    
         /usr/java/jdk1.5.0/bin
    
         [csc322@lee ~/bin]$ whichpath bin
    
         /usr/kerberos/bin
         /usr/local/bin
         /bin
         /usr/bin
         /home/graph/csc322/bin
         /usr/java/jdk1.5.0/bin
         /usr/X11R6/bin
    
         [csc322@lee ~/bin]$ whichpath Chattahoochee
         [csc322@lee ~/bin]$ 
    
    
    
  3. In one of my courses I had a prize hidden somewhere, and the students needed to break this secret message to find the prize:
       tluaqlaesd sda ialod mtsrfua sda ojerrqmmk
    
    Assuming that the code is a substitution of letters for letters, how many words are there with letter pattern tluaqlaesd (assume sda matches some common three letter word!). Use grep and /usr/share/dict/words to find out. Continue and find the secret message. Use sed with the y option to translate the encrpted message.