Need help with menu

Need help with menu

am 22.03.2007 02:08:45 von dantes990

I am creating a fairly basic menu driven script that will perform a
few different actions. Everything is working so far, except I'd like
to have an "Advanced Menu" option within the "Main" menu.


This is the logic I am going for:

I would like is to have the Main menu show up initially when you run
the script. There are several options to perform specific actions and
when the action is done it should return to the Main menu.

I would like one of the options to be an "Advanced menu" with other
actions that can be performed and return to the Advanced menu.

One of the actions in the Advanced Menu should return the user to the
Main menu.

Also, both menu's would have an option to Exit and return the user to
the command line.




I am currently using the Bourne shell, but I am open to alternatives
if there is something that would work better. The example below is
where I am stuck. I've tried a handful of different things without
luck, so now it is basically back to the point of just having the
functionality of the Main menu. If you can't tell, I am unsure as to
how to go between the Main and Advanced menu's, the logic I started
with for the Main menu doesn't seem to apply when adding another menu
into the picture. Any help is appreciated.


#!/bin/sh
amenu="1. Main 1"
bmenu="2. Main 2"
cmenu="3. Main 3"
dmenu="4. Advanced Menu..."
emenu="1. Adv 1"
fmenu="2. Adv 2"
gmenu="3. Adv 3"
hmenu="4. Adv 4"
imenu="5. Main Menu..."
mainexit="5. Quit"
advexit="6. Quit"


aaction () { echo ONE ; }
baction () { echo TWO ; }
caction () { echo THREE ; }
daction () { command to go to advanced menu ; }
eaction () { echo adv1 ; }
faction () { echo adv2 ; }
gaction () { echo adv3 ; }
haction () { echo adv4 ; }


mainmenu () {
clear
echo
echo
echo
echo " " Main Menu
echo
echo
echo " " $amenu
echo " " $bmenu
echo " " $cmenu
echo " " $dmenu
echo " " $mainexit
echo
echo
echo Choose a number and press Enter:
}


advmenu () {
clear
echo
echo
echo
echo " " Advanced Menu
echo
echo
echo " " $emenu
echo " " $fmenu
echo " " $gmenu
echo " " $hmenu
echo " " $imenu
echo " " $advexit
echo
echo Choose a number and press Enter:
}

while true
do
mainmenu
read answer
case $answer in
1) aaction;;
2) baction;;
3) caction;;
4) daction;;
5) Break;;
esac
done

Re: Need help with menu

am 22.03.2007 07:14:43 von sivaswamimail

replace

while true
do
mainmenu
read answer
case $answer in
1) aaction;;
2) baction;;
3) caction;;
4) daction;;
5) Break;;
esac
done

with

answer=0;
while [$answer != 6 ]
do
....
done




On Mar 22, 6:08 am, dantes...@yahoo.com wrote:
> I am creating a fairly basic menu driven script that will perform a
> few different actions. Everything is working so far, except I'd like
> to have an "Advanced Menu" option within the "Main" menu.
>
> This is the logic I am going for:
>
> I would like is to have the Main menu show up initially when you run
> the script. There are several options to perform specific actions and
> when the action is done it should return to the Main menu.
>
> I would like one of the options to be an "Advanced menu" with other
> actions that can be performed and return to the Advanced menu.
>
> One of the actions in the Advanced Menu should return the user to the
> Main menu.
>
> Also, both menu's would have an option to Exit and return the user to
> the command line.
>
> I am currently using the Bourne shell, but I am open to alternatives
> if there is something that would work better. The example below is
> where I am stuck. I've tried a handful of different things without
> luck, so now it is basically back to the point of just having the
> functionality of the Main menu. If you can't tell, I am unsure as to
> how to go between the Main and Advanced menu's, the logic I started
> with for the Main menu doesn't seem to apply when adding another menu
> into the picture. Any help is appreciated.
>
> #!/bin/sh
> amenu="1. Main 1"
> bmenu="2. Main 2"
> cmenu="3. Main 3"
> dmenu="4. Advanced Menu..."
> emenu="1. Adv 1"
> fmenu="2. Adv 2"
> gmenu="3. Adv 3"
> hmenu="4. Adv 4"
> imenu="5. Main Menu..."
> mainexit="5. Quit"
> advexit="6. Quit"
>
> aaction () { echo ONE ; }
> baction () { echo TWO ; }
> caction () { echo THREE ; }
> daction () { command to go to advanced menu ; }
> eaction () { echo adv1 ; }
> faction () { echo adv2 ; }
> gaction () { echo adv3 ; }
> haction () { echo adv4 ; }
>
> mainmenu () {
> clear
> echo
> echo
> echo
> echo " " Main Menu
> echo
> echo
> echo " " $amenu
> echo " " $bmenu
> echo " " $cmenu
> echo " " $dmenu
> echo " " $mainexit
> echo
> echo
> echo Choose a number and press Enter:
>
> }
>
> advmenu () {
> clear
> echo
> echo
> echo
> echo " " Advanced Menu
> echo
> echo
> echo " " $emenu
> echo " " $fmenu
> echo " " $gmenu
> echo " " $hmenu
> echo " " $imenu
> echo " " $advexit
> echo
> echo Choose a number and press Enter:
>
> }
>
> while true
> do
> mainmenu
> read answer
> case $answer in
> 1) aaction;;
> 2) baction;;
> 3) caction;;
> 4) daction;;
> 5) Break;;
> esac
> done