18.9. Menus

When creating menus, the null command comes in very handy with the while loop. A while and null combined mean loop forever, which is what we want for a menu, unless of course the user selects exit or a valid option.

To create a menu you need only a while loop and a case statement to catch all the patterns the user inputs. If an invalid input is given then sound the bell, echo a error message and then carry on with the loop until the user has finished his processing and selected the exit option.

A menu should also be friendly; the user should not have to guess what to do. The main screen would also look good with the hostname and date on it, coupled with the name of the user who is running the menu. For our test purposes, all the ...

Get Linux and Unix Shell Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.