Case Nesting


Login or Register to Reply

 
Thread Tools Search this Thread
# 2  
Hi,

Try this


Code:
#!/bin/bash

  clear
            # display menu

         echo "-------------------------------"
         echo "       Superman Restaurant"
         echo "-------------------------------"
         echo "            Main Menu"
         echo "-------------------------------"
         echo "   $(date)"
         echo "-------------------------------"
         echo "1. Display Meal Menu."
         echo "2. Display Drinks."
         echo "3. Display Desert."
         echo "4. Exit"
            # get input from the user

         read -p "Enter your choice [ 1 -4 ] " choice
            # make decision using case..in..esac
         case $choice in
                  1)
                            clear
         echo "-------------------------------"
         echo "       Superman Restaurant"
         echo "-------------------------------"
         echo "            Meal Menu"
         echo "-------------------------------"
         echo
         echo "1. Chichen Fried Rice    10RM."
         echo "2. Tom Yam Fried Rice    15RM."
         echo "3. Lovers Rice           10RM."
         echo "4. Curry Rice            12RM."
         echo "5. Jelof Rice            15RM."
         echo "6. Fairy Rice            10RM."
         echo "7. Spicy Stew Rice       18RM."
         echo "8. Exit"


         read -p "Enter your choice [ 1 -7 ] " Meal
         case $Meal in
         1) meal.txt
         Chichen Fried Rice > meal.txt
         echo " You Just Selected Chichen Fried Rice"
read -p "Press [Enter] to continue order..."

         if $readEnterKey true
         then

         echo
         echo "Your Order has been Completed"
         else
         echo ""
         fi
         ;;
         2)
         echo " You Just Selected Tom Yam Fried Rice"

         read -p "Press [Enter] to continue order..."
         if $readEnterKey true
         then

         echo
         echo "Your Order has been Completed"
         else
         echo ""
         fi
         ;;
         3)
         echo " You Just Selected Lovers Rice"
         read -p "Press [Enter] to continue order..."
         if $readEnterKey true
         then
         echo
         echo "Your Order has been Completed"
         else
         echo ""
         fi
        ;;
         4)
         echo " You Just Selected Curry Rice"
         read -p "Press [Enter] to continue order..."
         if $readEnterKey true
         then
         echo
echo "Your Order has been Completed"
         else
         echo ""
fi
         ;;
         5)
         echo " You Just Selected Jelof Rice"

         read -p "Press [Enter] to continue order..."
         if $readEnterKey true
         then

         echo
         echo "Your Order has been Completed"
         else
         echo ""
fi
         ;;
                 6)
         echo " You Just Selected Fairy Rice"

         read -p "Press [Enter] to continue order..."
         if $readEnterKey true
         then

         echo
         echo "Your Order has been Completed"
         else
         echo ""
fi
         ;;
                 7)
        echo " You Just Selected Spicy Rice"

         read -p "Press [Enter] to continue order..."
         if $readEnterKey true
         then

         echo
         echo "Your Order has been Completed"
         else
         echo ""
fi
;;
                  8)

          echo "Bye!"
                                  exit 0
                                  ;;
          *)
             echo "Error: Invalid option..."
             read -p "Press [Enter] key to continue..."

                                  ;;

esac
;;
                 2)
                            clear
         echo "-------------------------------"
         echo "       Superman Restaurant"
         echo "-------------------------------"
         echo "            Drinks Menu"
         echo "-------------------------------"
         echo
         echo "1. Kikapo Juice     2RM."
         echo "2. Orange Juice     3RM."
         echo "3. Apple Juice      3RM."
         echo "4. Lemon Ice Tea    1RM."
         echo "5. Mango Lassi      5RM."
         echo "6. Herba Tea        2RM."
         echo "7. Cococola         2RM"
         echo "8. Bye!"
         read -p "Enter your choice [ 1 -8 ] " Drinks
         case $Drinks in
             1)
         echo " You Just Selected Kikapo Juice"

         read -p "Press [Enter] to continue order..."

         if $readEnterKey true
         then

         echo
         echo "Your Order has been Completed"
 else
         echo ""
         fi
        ;;
          2)
         echo " You Just Selected Orange Juice"

         read -p "Press [Enter] to continue order..."

         if $readEnterKey true
         then

         echo
         echo "Your Order has been Completed"
         else
         echo ""
fi
;;
         3)echo " You Just Selected Apple Juice"
         read -p "Press [Enter] to continue order..."

         if $readEnterKey true
         then

         echo
         echo "Your Order has been Completed"
         else
         echo ""
fi
;;
          4)echo " You Just Selected Lemon Juice"
         read -p "Press [Enter] to continue order..."

         if $readEnterKey true
         then

         echo
         echo "Your Order has been Completed"
         else
         echo ""
fi
;;
 5)echo " You Just Selected Mango Juice"
         read -p "Press [Enter] to continue order..."

         if $readEnterKey true
         then

         echo
         echo "Your Order has been Completed"
         else
         echo ""

fi
;;
         6)echo " You Just Selected Herbal Tea"
         read -p "Press [Enter] to continue order..."

         if $readEnterKey true
         then

         echo
         echo "Your Order has been Completed"
         else
         echo ""
fi
;;
         7)echo " You Just Selected Cocacola"
         read -p "Press [Enter] to continue order..."

         if $readEnterKey true
         then

         echo
         echo "Your Order has been Completed"
         else
         echo ""
fi
;;
         8)echo "Bye!"
                                  exit 0
                                  ;;
          *)
             echo "Error: Invalid option..."
 read -p "Press [Enter] key to continue..."

                                  ;;
            esac
;;
                            3)

                            clear
         echo "-------------------------------"
         echo "       Superman Restaurant"
         echo "-------------------------------"
         echo "            Desert Menu"
         echo "-------------------------------"
         echo
         echo "1. Ferry Cake               15RM."
         echo "2. Chocolate ice Cream      10RM."
         echo "3. Vanilla Cake             13RM."
         echo "4. Queen Cake               12RM."
         echo "5. Bye!"
         read -p "Enter your choice [ 1 -5 ] " Desert
         case $Desert in
             1)
         echo " You Just Selected Ferry Cake"

         read -p "Press [Enter] to continue order..."

         if $readEnterKey true
         then

         echo
         echo "Your Order has been Completed"
         else
         echo ""
fi
;;
          2)
         echo " You Just Selected Chocolate ice Cream"

         read -p "Press [Enter] to continue order..."
if $readEnterKey true
         then

         echo
         echo "Your Order has been Completed"
         else
         echo ""
fi
;;
         3)
         echo " You Just Selected Vanilla Cake"

         read -p "Press [Enter] to continue order..."

         if $readEnterKey true
         then

         echo
         echo "Your Order has been Completed"
         else
         echo ""
fi
;;
          4)
        echo " You Just Selected Queen Cake"

         read -p "Press [Enter] to continue order..."

         if $readEnterKey true
         then

         echo
         echo "Your Order has been Completed"
         else
         echo ""

fi
;;
         5)


          echo "Bye!"
                                  exit 0
                                  ;;
          *)
             echo "Error: Invalid option..."
             read -p "Press [Enter] key to continue..."

                                  ;;
            esac
;;

          4)

           echo "Bye!"
                                  exit 0
                                  ;;
          *)
             echo "Error: Invalid option..."
             read -p "Press [Enter] key to continue..."

                                  ;;



esac

# 3  
kindly find below the case command syntax:-

Code:
case "$variable" in
"$condition1" )
command...
;;
"$condition2" )
command...
;;
esac

Notes:-
1-Each test line ends with a right paren ).
2-Each condition block ends with a double semicolon ;;.
3-The entire case block terminates with an esac (case spelled backwards).
4-Quoting the variables is not mandatory, since word splitting does not take
place.

Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Issue nesting variables in csh.
ojdefdidit
The variables given are already defined ($file1-$file3, $obsid1-$obsid3, and $n=3). When I go to run the code, the terminal outputs "Missing }." I believe the error is with the nesting of variables. It would save a lot of time getting this while loop working. set i = 1 while (${i} <=...... Shell Programming and Scripting
5
Shell Programming and Scripting
Bash - Nesting if statement in for loop
ncwxpanther
I have the basic command written in bash for element in 1 2 do if ]; then set el = "t" else set el = "p" fi done but i get the following error syntax error near unexpected token `for' ` for element in 1 2' What should i do differently?... Shell Programming and Scripting
3
Shell Programming and Scripting
Nesting backticks
Starting_Leaf
I'm trying to make a dialog window that prints the output of grep that takes the output of find. Unfortunately my nested backticks don't work. Here is the dialog window: dialog --stdout --title "test" --backtitle "test" --msgbox "Test:\n `grep -l "${tablica}" `find $string``" 16 60I think I...... Shell Programming and Scripting
2
Shell Programming and Scripting
How to ignore STDERR when nesting commands?
Smiling Dragon
I have a pel script running as root that needs to read the contents of a file on a remote system, I have an ssh trust relationship as a particular user but not as root. I then need to write back out to that file again to change it's content a bit. On the surface this seemed really easy but...... Shell Programming and Scripting
3
Shell Programming and Scripting
zip nesting empty folders
groundlevel
I'm using the following command to zip a project file, but when it finishes, the resulting zip file contains all the directories above the file I wanted zipped, myapp.app, each one empty until you get to the actual app. zip -r myapp.app.zip ...... UNIX for Dummies Questions & Answers
0
UNIX for Dummies Questions & Answers