Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Tie submenus to Main Menu

Status
Not open for further replies.

navarro1

Technical User
Jun 11, 2003
9
US
This is the script for the main menu:
$ MainMenu
echo " Please choose from the above options : \c"
read option
case $option in
[Dd] ) echo "You have chosen to Display student" ;;
[Aa] ) echo "You have chosen to Add a student" ;;
[Ee] ) echo "You have chosen to Edit a student" ;;
[Ss] ) echo "You have chosen to Sort a student" ;;
[Hh] ) echo "You have chosen Help" ;;
[Xx] ) echo "You have chosen to Exit" ;;

esac

If the user choose e for edit I would like the screen display the Edit Menu on the screen like this:

You have chosen to Edit\delete a student:
1)Edit Student
2)Delete Student
3)Help
4)Exit to Main Menu
Enter Selection >

Do I write a script for the edit menu and then insert below
[Ee] ) echo "You have chosen to Edit a student"
clear
while true
do
edit.text
or someting like this to have the second level of menu options run?

 
Just make each menu / submenu a separate function

Code:
#!/bin/sh

# the edit function and it's menu
function edit_menu {
  echo "1)Edit Student"
  echo "2)Delete Student"
  echo "3)Help"
  echo "4)Exit to Main Menu"
  echo -e "Enter Selection > \c"
}

function sub_edit {
  while true ; do
    edit_menu
    read option
    case $option in
      [1] ) echo "You have chosen to Edit student" ;;
      [2] ) echo "You have chosen to Delete student" ;;
      [3] ) echo "You have chosen Help" ;;
      [4] ) echo "You have chosen to Exit"
            break ;;
    esac 
  done
}

# the main function and it's menu
function main_menu {
  echo "D - Display" 
  echo "A - Add"
  echo "E - Edit"
  echo "S - Sort"
  echo "H - Help"
  echo "X - Exit"
  echo -e " Please choose from the above options : \c"
}

function main {
  while true ; do
    main_menu
    read option
    case $option in
      [Dd] ) echo "You have chosen to Display student" ;;
      [Aa] ) echo "You have chosen to Add a student" ;;
      [Ee] ) echo "You have chosen to Edit a student"
             sub_edit ;;
      [Ss] ) echo "You have chosen to Sort a student" ;;
      [Hh] ) echo "You have chosen Help" ;;
      [Xx] ) echo "You have chosen to Exit"
             break ;;
    esac 
  done
}

# go do it all
main
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top