The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 06-27-2005
google's Avatar
google google is offline Forum Advisor  
Moderator
  
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
Change the "if" line to this: Note there the spaces after the "[" and before the "]" are required. Also, to access the value of a variable in shell, prefix the variable with a "$" sign. Use "fi" to close the "if" statement.


Code:
if [ $choice -eq 1 ] then
echo "This is reading the first choice"
fi

You can clean up your code by using a "select case" which will build the menu for you. Here is the syntax (note that the ";;" must end every case.)

Code:
select NUM in 1 2 3 quit
do
   case $NUM in
      1)  echo "This is reading the first choice"
           ;;
      2)  echo "This is reading the second choice"
           ;;
      3)  echo "This is reading the third choice"
           ;;
    quit) echo "Goodbye"
           exit;;
   esac
done

Lastly, to fancy it up a bit, use the builtin variable PS3 to set your prompt string for the menu (Add it just before the "select case" statement)

Code:
PS3="Make a Selection From the Following List"


Last edited by google; 06-27-2005 at 09:05 AM..