ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am trying to write a shell script that displays a menu with 22 options of commands. I would like to have an option to display another menu of more options, but I can't get it to function properly. I am using a while loop with case for the options. Any help would be greatly appreciated.
There is not an error, just a lack of function. I would like to display the first menu, then if selected the second and then the third. I have been able to display the first, but then I am only able to go the second or third from the first. If I try to go to the third menu from the second menu, it goes to the Wait() and then returns to the first menu. I hope this helps clarify my issue.
bash has a builtin command "select" which you may find useful instead of coding it up yourself. From man bash or "help select"
Code:
$ help select
select: select NAME [in WORDS ... ;] do COMMANDS; done
The WORDS are expanded, generating a list of words. The
set of expanded words is printed on the standard error, each
preceded by a number. If `in WORDS' is not present, `in "$@"'
is assumed. The PS3 prompt is then displayed and a line read
from the standard input. If the line consists of the number
corresponding to one of the displayed words, then NAME is set
to that word. If the line is empty, WORDS and the prompt are
redisplayed. If EOF is read, the command completes. Any other
value read causes NAME to be set to null. The line read is saved
in the variable REPLY. COMMANDS are executed after each selection
until a break command is executed.
lewc, I started the rewrite but my coworkers thought that a multilevel menu was not simple enough. I ended up rewriting the menu to display 3 rows with all of the options for the user. I appreciate the information and advise you gave me and I will use it in my scripts at home. I guess that sometimes simple is better (for the end user). Thanks also to lwasserm for the post about using select.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.