Previous Section  < Day Day Up >  Next Section

LAB 45: THE case STATEMENT

  1. Write a script 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 this program.

    2. Convert the following program using case statements:

      
      # The timegreet script by Ellie Quigley
      
      you=$LOGNAME
      
      hour=`date | awk '{print substr($4, 1, 2)}'`
      
      print "The time is: $(date)"
      
      if (( hour > 0 && $hour < 12 ))
      
      then
      
           print "Good morning, $you!"
      
      elif (( hour == 12 ))
      
      then
      
           print "Lunch time!"
      
      elif (( hour > 12 && $hour < 16 ))
      
      then
      
           print "Good afternoon, $you!"
      
      else
      
           print "Good night, $you!"
      
      fi
      
      

  2. Rewrite the lookup script, replacing the if/elif construct with the case command. Add one more menu item:

    
    1) Add Entry
    
    2) Delete Entry
    
    3) Update Entry
    
    4) View Entry
    
    5) Exit
    
    

    Previous Section  < Day Day Up >  Next Section