The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #5 (permalink)  
Old 05-13-2008
Cameron's Avatar
Cameron Cameron is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2001
Location: Brisbane, Australia
Posts: 500
It's easier to understand when you format your code so that's more manageable to work with and read ...

Code:
select action in "blabla" "blabla" "quit" 
do

  case $action in
    "blabla")  echo "I was passed blabla."
               echo "Now executing a command..."
               somecommandhere ;;  #.... for each possible command in $action
    "quit")    break ;;
    *)         print "this is not an option, try again" ;;
  esac

done

The select statement reads the values after 'in' ... "blabla" "blabla" "quit" .
Then selects each one in turn and passes the value to $action to use within the select statement.
$action is used in the case statement, here the value is compared to those listed values contained within the case statement and if a match is made, executes the code attached to that match. If the value of $action doesn't match any value contained within the case statement, then it is passed to (or rather picked-up by) the statements associated with '*'.

Hope that ruff explaination is of some benefit.

Cheers,
Cameron