Linux Shell Scripting Tutorial (LSST) v1.05r3 | ||
Chapter 4: Advanced Shell Scripting Commands | ||
|
Its time to write script to create menus using dialog utility, following are menu items
Date/time
Calendar
Editor
and action for each menu-item is follows :
MENU-ITEM | ACTION |
Date/time | Show current date/time |
Calendar | Show calendar |
Editor | Start vi Editor |
$ cat > smenu |
Save it and run as:
$ rm -f /tmp/menuitem.$$
$ chmod +x smenu
$ ./smenu
--menu option is used of dialog utility to create menus, menu option take
--menu options | Meaning |
"Move using [UP] [DOWN],[Enter] to Select" | This is text show before menu |
15 | Height of box |
50 | Width of box |
3 | Height of menu |
Date/time "Shows Date and Time" | First menu item called as tag1 (i.e. Date/time) and description for menu item called as item1 (i.e. "Shows Date and Time") |
Calendar "To see calendar " | First menu item called as tag2 (i.e. Calendar) and description for menu item called as item2 (i.e. "To see calendar") |
Editor "To start vi editor " | First menu item called as tag3 (i.e. Editor) and description for menu item called as item3 (i.e."To start vi editor") |
2>/tmp/menuitem.$$ | Send selected menu item (tag) to this temporary file |
After creating menus, user selects menu-item by pressing the ENTER key, selected choice is redirected to temporary file, Next this menu-item is retrieved from temporary file and following case statement compare the menu-item and takes appropriate step according to selected menu item. As you see, dialog utility allows more powerful user interaction then the older read and echo statement. The only problem with dialog utility is it work slowly.
| ||
Input (inputbox) using dialog utility | trap command |