Lab 8




As with previous labs, set up an appropriate directory. Get feedback on your work from the TA (only) during the lab. And submit your work with the command
$ submit 2031 lab8 scritp1
$ submit 2031 lab8 scritp2
$ submit 2031 lab8 scritp3
$ submit 2031 lab8 scritp4

The Exercise

Since lab 7 was rather long, you should continue working on it and then turn to the material for this lab. In this lab you should try writing Bourne/bash shell commands and scripts to demonstrate/learn/check the material of the slides used in class, in particular

Bourne/Bash Shell

Ask the TAs for help, if you do not understand a concept or cannot make something work. DO NOT just read the slides - actually write some commands/scripts to work with them.

This material will be tested in upcoming lab tests and on the final exam. Start working your way through it.

You should also get started writing small shell scripts.
  1. Write, test and submit a bash shell script called script1 that prints out its command line arguments (not the command name), one per line. Test runs of the program should look like this:
    $
    $ script1
    $ script1 a b     hello
    a
    b
    hello
    $
    

  2. Write, test and submit a bash shell script called script2 that behaves like script1 except that it outputs its commandline arguments in sorted order. Test runs of the program should look like this:
    $
    $ script2
    $ script2 hello  goodbye zzz aa
    aa
    goodbye
    hello
    zzz
    $
    

  3. Write, test and submit a bash shell script called script3 that outputs its commandline arguments, along with the argument number, exactly as shown in the following examples:
    $
    $ script3
    $ script3 Hello
    arg number 1 is Hello
    $ script3 Hello Goodbye c b a
    arg number 1 is Hello
    arg number 2 is Goodbye
    arg number 3 is c
    arg number 4 is b
    arg number 5 is a
    $
    

  4. Write, test and submit a bash shell script called script4. script4 should print out, one per line, the "real names" of all users with an account on the system whose login names begin with the script's first commandline argument. If there is not exactly 1 commandline argument, then a usage message (exactly like that in the examples) should be written to standard error (not standard out). See the following examples.

    In particular, see the error message when the wrong number of commandline args is used when the full pathname of the command is given or the name of the command has been changed (so you can't just hardcode 'script4' into your error message).
    $
    $ script4
    Usage: script4 <logname or logname prefix>  <-- written to standard error
    $ script4 ali bil
    Usage: script4 <logname or logname prefix>  <-- written to standard error
    $ /cs/dept/www/course/2031/script4 firstArg secondArg
    Usage: script4 <logname or logname prefix>  <-- written to standard error
    $ mv script4 fourthScript
    $ /cs/dept/www/course/2031/fourthScript firstArg secondArg
    Usage: fourthScript <logname or logname prefix>  <-- written to standard error
    $ mv fourthScript script4
    $ ./script4 a b c
    Usage: script4 <logname or logname prefix>  <-- written to standard error
    $ script4 ali
    Ali Mahmoodi
    alireza moghaddam
    $ script4 al
    Albert Rothenstein
    alborz Workstation
    Alexander Andreopoulos
    Ali Mahmoodi
    alireza moghaddam
    Robert S Allison
    $ script4 bi
    bin
    Vassilios Tzerpos
    Bill Andreopoulos
    Bill Kapralos
    Bita Banihashemi
    $
    

end of lab 8