LAB 59: THE case STATEMENT

 <  Day Day Up  >  

LAB 59: THE case STATEMENT

  1. The ps command is different on BSD (Berkeley UNIX), System 5 (AT&T UNIX), and Linux. On System 5, the command to list all processes is

     ps ef 

    On BSD UNIX, the command is

     ps aux 

    On Linux, the command is

     ps -aux 

    Write a program called systype that will check for a number of different system types. The cases to test for will be

    AIX

    Darwin (Mac OS X)

    Free BSD

    HP-UX

    IRIX

    Linux

    OS

    OSF1

    SCO

    SunOS (Solaris/SunOS)

    ULTRIX

    Solaris, HP-UX, SCO, and IRIX are AT&T-type systems. The rest are BSD-ish.

    The version of UNIX you are using will be printed to stdout . The system name can be found with the uname “s command or from the /etc/motd file.

  2. Write a script called timegreet that will do the following:

    1. Provide a comment section at the top of the script, with your name, the date, and the purpose of the program.

    2. Convert the following program to use the case command rather than if/elif .

     #!/bin/bash  # Comment section  you=$LOGNAME hour=$(date +%H) echo "The time is: $(date +%T)" if ((hour > 0 && hour < 12)) then    echo "Good morning, $you!" elif ((hour == 12)) then    echo "Lunch time!" elif ((hour > 12 && hour < 16)) then    echo "Good afternoon, $you!" else    echo "Good night, $you. Sweet dreams." fi 

 <  Day Day Up  >  


UNIX Shells by Example
UNIX Shells by Example (4th Edition)
ISBN: 013147572X
EAN: 2147483647
Year: 2004
Pages: 454
Authors: Ellie Quigley

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net