Operating System - HP-UX
1834274 Members
1983 Online
110066 Solutions
New Discussion

menu scrpit question (loop)

 
SOLVED
Go to solution
someone_4
Honored Contributor

menu scrpit question (loop)

I have attached a menu script.
And it works great. But I have a main menu,
and a sub menu as shown in the attachment.
But from the submenu I execute a choice and tail the log and break out of the log it takes me to the main menu. But I would like it to take me back to submenu1 not the main menu.
And then from the submenu1 I can break out to the main menu. Is there a way to do that or do i always have to go back to the main menu?
12 REPLIES 12
someone_4
Honored Contributor

Re: menu scrpit question (loop)

I am planning on adding more submenus with other options. But I want them to all go back to the sub menu , not the main menu.
thanks
Maureen Gunkel
Trusted Contributor

Re: menu scrpit question (loop)

Richard,
If you change your 'if [ "${X}" -eq "1" ]; then' statement to a 'while [ "${X}" -eq "1" ]; do' statement (and change the matching 'fi' to a 'done', that should do the trick. I have one like yours, with sub-menus, and if you'd like I'll post it for you.
Hope this helps,
Mo
No matter where you go, there you are.
someone_4
Honored Contributor

Re: menu scrpit question (loop)

ok I just tried that.. but now from the submenu
I cant break back the the main menu.
James R. Ferguson
Acclaimed Contributor

Re: menu scrpit question (loop)

Richard:

One way to structure menu scripts like this is to form an outer 'while true do' loop which uses a case statement to call functions within you shell script. Each function can have its own 'while true do' loop to select, read, case, etc. Use 'return' to exit the function back to the outer loop, etc.

...JRF...
Maureen Gunkel
Trusted Contributor
Solution

Re: menu scrpit question (loop)

Richard,
If you add a line like:
echo " 0) Return to main menu \n"
when the user presses 0, change the assignment of variable 'X' to 0, then it won't be equal to 1 anymore.
By the way, I have posted my script, you can take what you want from it. It's real long, and kinda involved, but look for the 'REALSTART' part, and that'll get you started.
Peace!
Mo
No matter where you go, there you are.
someone_4
Honored Contributor

Re: menu scrpit question (loop)

ok .. that last one lost me .. which X do I change. Attached is what I changed so far.
someone_4
Honored Contributor

Re: menu scrpit question (loop)

ok .. that last one lost me .. which X do I change. Attached is what I changed so far.
But I dont understand where you want me to change X. With this one I get to the sub menu, but that is where i get stuck. I cant break out of the sub menu back to the main menu.

Maureen Gunkel
Trusted Contributor

Re: menu scrpit question (loop)

Richard,
I'm working on it. I'll attach a revised copy when I figure it out.
Mo
No matter where you go, there you are.
someone_4
Honored Contributor

Re: menu scrpit question (loop)

Ok here is what I have I added :
X=99
while [ ! $X -eq 0 ]
---
and if you look at option 3 it reads the 99.
---
I know 3 menus deep is too much.. But im just wondering if I did. can I put
X=99
X=98
X=97
---
to control what menu the sub or sub/sub will go? I may try that just for fun later on.
someone_4
Honored Contributor

Re: menu scrpit question (loop)

OHHH .. IT ALL WORKS TOO !!
Forgot to mention that.. thanks for all your help.

Richard ..
Joseph C. Denman
Honored Contributor

Re: menu scrpit question (loop)

This is what Maureen is saying.

#Add Another choice to your list
echo "PRESS '3' to exit"

#Add the choice
#choice 3
if [ "${Y}" -eq "3" ];then
clear
X=2
fi

This will make X != 1 thus exiting the look for the submenu and returning you to the main menu
If I had only read the instructions first??
someone_4
Honored Contributor

Re: menu scrpit question (loop)

=)
Yeah after taking a break and looking at it .. it hit me like a ton of bricks !