Linux Shell Scripting Tutorial (LSST) v1.05r3
Prev
Chapter 4: Advanced Shell Scripting Commands
Next

User Interface using dialog Utility - Putting it all together

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/timeShow current date/time
CalendarShow calendar
EditorStart vi Editor

$ cat > smenu
#
#How to create small menu using dialog
#
dialog --backtitle "Linux Shell Script Tutorial " --title "Main\
Menu" --menu "Move using [UP] [DOWN],[Enter] to\
Select" 15 50 3\
Date/time "Shows Date and Time"\
Calendar "To see calendar "\
Editor "To start vi editor " 2>/tmp/menuitem.$$

menuitem=`cat /tmp/menuitem.$$`

opt=$?

case $menuitem in
Date/time) date;;
Calendar) cal;;
Editor) vi;;
esac

Save it and run as:
$ rm -f /tmp/menuitem.$$
$ chmod +x smenu
$ ./smenu

User Interface using dialog Utility - Putting it all together

--menu option is used of dialog utility to create menus, menu option take

--menu optionsMeaning
"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.


Prev
Home
Next
Input (inputbox) using dialog utility
Up
trap command