Reputation: 23
There is 2 things i'm not sure about which i have been trying to do for a while and i'm sorry for sounding stupid, but i'm not sure where to integrate the code so that when option A or B is pressed in the Sub Menus it says "Option A Selected" I'm also not sure how to loop the Sub Headings so that when it has said "Option A/B Selected" it goes back to the sub menu screen. Until i Press the back to main menu button when it will go to the Main Menu. I'd much appreciate any help as i am new to this and struggling with this bit in particular, Thanks!
Upvotes: 1
Views: 8923
Reputation: 185015
Another approach :
select x in submenu1 submenu2 exit ; do
[[ $x == exit ]] && exit 0
select y in optionA optionB; do
echo "submenu $y heading"
echo "$x selected"
break
done
done
1) submenu1
2) submenu2
3) exit
> 1
1) optionA
2) optionB
> 1
submenu optionA heading
submenu1 selected
>
Upvotes: 1
Reputation: 17258
One way of simplifying the task is to keep each menu in it's own function, Each menu loops until the user presses the exit key. In this case 'x' is used. My bash does not
function subopt1
{
subopt1=""
while [ "$subopt1" != "x" ]
do
echo Sub Menu 1 Heading
echo Option A
echo Option B
echo x Back to Main Menu
read -p "Select sub option1" subopt1
done
}
function subopt2
{
subopt2=""
while [ "$subopt2" != "x" ]
do
echo Sub Menu 2 Heading
echo Option A
echo Option B
echo x Back to Main Menu
read -p "Select sub-option2" subopt2
done
}
function mainopt
{
opt=""
while [ "$opt" != "x" ]
do
echo Menu Heading
echo Sub Menu 1
echo Sub Menu 2
read -p "Select Otion: " opt
if [ "$opt" = "1" ]; then
subopt1
elif [ "$opt" = "2" ]; then
subopt2
elif [ "$opt" = "x" ];then
break
fi
done
}
mainopt
Upvotes: 0