Menu Command


menu [-f firstmenu] menuname


The menu command replaces the current menu with menuname. The menuname argument may either name a menu description in the current menufile, or it may name another menufile. In the latter case, the new menufile replaces the current menufile, and the first menu is displayed in the new menufile (if the -f flag is used, firstmenu is displayed). The menu command does not call itself recursively each time a new menu is displayed.

The menu command is only recognized if it is the last command in the group of commands for a menufile, menu or choice. When a group of commands are executed, menu passes all the commands that precede the menu command to the shell (or to the menu command processor if built-in menu commands are enabled) to be executed. If the shell (or menu command processor) returns an exit status of zero, the menu command is executed.

Menu requires that every menu file must contain at least one menu or quit command. Otherwise, it may not be possible to exit from the menu.

In the example that follows, all the commands preceding the menu command are passed to the shell (built-in menu commands are disabled).


if test ! file newmenufile


echo "newmenufile does not exist"

exit 1


exit 0

menu newmenufile

In the above example, menu only displays the first menu in newmenufile if the exit status returned from the menu command processor is zero. When the choice is selected, menu passes all the commands that come before the menu command, menu newmenufile, to the shell to be executed. If newmenufile does not exist, a message is displayed on the screen and no more commands are executed. If newmenufile does exist, the if command, since it has failed, returns a non zero exit status. So the exit status must be set to zero so the menu newmenufile command can be run. The menu command menu should never be included in a command that is passed to the menu command processor (i.e. if, while, etc.) because doing so would cause menu to be called recursively.