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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create a Submenu using shell scripting

Status
Not open for further replies.

sivhaga

IS-IT--Management
Jun 3, 2008
25
Hi,

I have created a menu script having 3 main option.It works well. But I would like to have a submenus within an option.

Eg. 1.Start - ATP
- BILLING
2.Check - ATP
- BILLING
3.Kill - ATP
- BILLING
Therefore the only code that i can only Start ATP,Check ATP and Kill ATP. How do i add a submenu BILLING like if you choose to Start, then it has to display two options either you want to start ATP or BILLING.

My code so far is

while :
do
clear
echo "=================================================================================================== ===="
banner " ATP MENU"
echo " 1. Check all running processes"
echo " 2. Start all processes"
echo " 3. Kill all processes"
echo " Q. Quit"
echo "=================================================================================================== ===="
echo "Enter your menu choice [1-3 or q]: "

read userinput
case $userinput in

1) echo "Check all option selected\n\n"
CHECKATP
echo "Press any key to continue" ; read ;;
2) echo "Start all option selected\n\n"
STARTATP
echo "Press any key to continue" ; read ;;
3) echo "Kill all option selected"
echo "Press any key to continue" ; read ;;
[qQ]*) exit 0 ;;
*) echo "Please select choice 1,2,3 or q";
echo "Press any key to continue" ; read ;;
esac
done
 
You have to create a loop within a loop!

Code:
while :
do
clear
echo "=================================================================================================== ===="
banner " ATP MENU"
echo "                    1. Check all running processes"
echo "                    2. Start all processes"
echo "                    3. Kill  all processes"
echo "                    Q. Quit"
echo "=================================================================================================== ===="
echo "Enter your menu choice [1-3 or q]: "

read userinput
case $userinput in

1) echo "Check all option selected\n\n"
   CHECKATP
while :
do
clear
echo "=================================================================================================== ===="
banner " ATP MENU"
echo "                    1. Check all running processes"
echo "                    2. Start all processes"
echo "                    3. Kill  all processes"
echo "                    Q. Quit"
echo "=================================================================================================== ===="
echo "Enter your menu choice [1-3 or q]: "

read userinput
case $userinput in

1) echo "ATP Submenu option selected\n\n"
   ATP
   echo "Press any key to continue" ; read ;;
2) echo "Billing option selected\n\n"
   BILLING
   echo "Press any key to continue" ; read ;;
[qQ]*) exit 0 ;;
*) echo "Please select choice 1,2 or q";
   echo "Press any key to continue" ; read ;;
esac
done
  
   echo "Press any key to continue" ; read ;;
2) echo "Start all option selected\n\n"
   STARTATP
   echo "Press any key to continue" ; read ;;
3) echo "Kill all option selected"
   echo "Press any key to continue" ; read ;;
[qQ]*) exit 0 ;;
*) echo "Please select choice 1,2,3 or q";
   echo "Press any key to continue" ; read ;;
esac
done

I've done it only on option 1 but you can generalize it for the rest!

Regards,
Khalid
 
Something along the lines of
Code:
#!/bin/ksh

while :
do
  #Top menu
  while :
  do
    echo "Select from
  ATM (a)
  Billing (b)
  Quit (q)"
    read type
    case $type
      a|A|b|B) break;;
      q|Q) exit;;
    esac
  done

  while :
  do
    #Second menu
    echo "Select from
  Check (1)
  Start (2)
  Kill  (3)
  Quit  (q)"
    read ans
    case $ans
      1) 
        [[ $type = 'a' || $type = 'A' ]] && CheckATM
        [[ $type = 'b' || $type = 'B' ]] && CheckBilling
        ;;
      2) 
        [[ $type = 'a' || $type = 'A' ]] && StartATM
        [[ $type = 'b' || $type = 'B' ]] && StartBilling
        ;;
      3) 
        [[ $type = 'a' || $type = 'A' ]] && KillATM
        [[ $type = 'b' || $type = 'B' ]] && KillBilling
        ;;
      q) exit;;
    esac
  done
done


On the internet no one knows you're a dog

Columb Healy
 
Looks like Khalid and I posted the same answer simultaneously!

On the internet no one knows you're a dog

Columb Healy
 
I just discovered that you will need to change the echo in the submenu :) copy paste error :)
 
Hi khalidaaa,

Can you please check the Columb Healy code and test it how it should perform, I like yours because it is quiet simple but the problem is it doesnt work.

Can you please test your code and if it works paste it for me here.You also mentioned that i have to change the echo, im lost, where, please test it and give me the working code.

Thank you so much for all the effort.
 
Ok. let me get this straight. How would the output of the menus look like?

1. Check all running processes"
1. ATP
2. Billing
Q. Quit back to main menu
2. Start all processes"
1. ATP
2. Billing
Q. Quit back to main menu
3. Kill all processes"
Q. Quit"


Would it be the above? please advice.

Regards,
Khalid
 
Yes, that is exactly what i will be looking for.
 
There you go:

Code:
while :
do
clear
echo "=================================================================================================== ===="
banner " ATP MENU"
echo "                    1. Check all running processes"
echo "                    2. Start all processes"
echo "                    3. Kill  all processes"
echo "                    Q. Quit"
echo "=================================================================================================== ===="
echo "Enter your menu choice [1-3 or q]: "

read userinput
case $userinput in

1) echo "Check all option selected\n\n"
   CHECKATP
while :
do
clear
echo "=================================================================================================== ===="
banner " ATP SubMENU"
echo "                    1. ATP"
echo "                    2. BILLING"
echo "                    Q. Return Back to Main Menu"
echo "=================================================================================================== ===="
echo "Enter your menu choice [1, 2 or q]: "

read userinput
case $userinput in

1) echo "ATP Submenu option selected\n\n"
   ATP
   echo "Press any key to continue" ; read ;;
2) echo "Billing option selected\n\n"
   BILLING
   echo "Press any key to continue" ; read ;;
[qQ]*) exit 0 ;;
*) echo "Please select choice 1,2 or q";
   echo "Press any key to continue" ; read ;;
esac
done
  
   echo "Press any key to continue" ; read ;;
2) echo "Start all option selected\n\n"
   STARTATP
while :
do
clear
echo "=================================================================================================== ===="
banner " ATP SubMENU"
echo "                    1. ATP"
echo "                    2. BILLING"
echo "                    Q. Return Back to Main Menu"
echo "=================================================================================================== ===="
echo "Enter your menu choice [1, 2 or q]: "

read userinput
case $userinput in

1) echo "ATP Submenu option selected\n\n"
   ATP
   echo "Press any key to continue" ; read ;;
2) echo "Billing option selected\n\n"
   BILLING
   echo "Press any key to continue" ; read ;;
[qQ]*) exit 0 ;;
*) echo "Please select choice 1,2 or q";
   echo "Press any key to continue" ; read ;;
esac
done

   echo "Press any key to continue" ; read ;;
3) echo "Kill all option selected"
   echo "Press any key to continue" ; read ;;
[qQ]*) exit 0 ;;
*) echo "Please select choice 1,2,3 or q";
   echo "Press any key to continue" ; read ;;
esac
done

I don't have an aix box for now to test this though! and i don't really know what do you mean by ATP and BILLING so i can't really test the whole functionality unless i know exactly what is in your mind :)

But it should work!

Regards,
Khalid
 
Or you could use winsmit to create a smit like menu.

Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
...and remember to thank people for help above and beyond with a little purple star ;-)

I want to be good, is that not enough?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top