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

Menu help

Status
Not open for further replies.

alan147

Technical User
Nov 15, 2002
128
GB
Good morning

I have written a simple menu to be used on a comms server the result is that when a user dials in and logs in they go straight to the menu. From the menu they can then telnet across to one of a number of Unix boxes.

What I want to be able to do is to make the user return to the menu when they exit out of the telnet session instead of the unix prompt on the comms server. Does anyone have any suggestions?

I am using bash.

Thanks

Alan
 
You could use a while loop...

EXITNOW="NO"
while [ $EXITNOW = "NO" ]
do
: menu
done
 
Thanks Ygor it works just as I wanted.
 
What if you have a sub-menu? How can you return from the submenu to the main menu. This is the list of my loops:
while:
do

until valid choice
...display main menu
done

while :
do
...
case
test input if q go to the main menu
esac
process information
done
done

If I break in submenu case it keeps bringing me back to the same submenu. If I break 2 it exit all together.

Thanks
AB
 
I would not recommend using the "while true" infinite loop construct at all. If you do, then you have to use "break" or "continue" exit from the loop. This violates the "single entry / single exit" rule for good programming style, much in the same way as "go to".

Why not use conditional loops, with flags for both the main loop and the sub?

EXITMAIN="NO"
while [ $EXITMAIN = "NO" ]
do
: menu
if : user chose to quit
then
EXITSUB="YES"
EXITMAIN="YES"
else
EXITSUB="NO"
fi
while [ $EXITSUB = "NO" ]
do
: submenu
done
done
 
Thanks for the suggestion. I figured out what was wrong. When you were exiting from the sub-menu,there was a validchoice already and it was just falling right through. I might have to change the code to not use breaks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top