Skip to content

Examples of menus

pgen edited this page Sep 6, 2018 · 3 revisions
  • Examples 1

    Here is how to create a trivial embedded menu to illustrate the concept

    $ cat menu1

    " 1 Item 1"
    " 2 Item 2"
    " 3 Item 3"
    " 4 Item 4"
    -
    " 0 Exit"
    

    $ cat menu1.sh

    #!/bin/sh
    
    ENTRY=999
    
    while [ $ENTRY -ne 0 ]; do
      LINE=$(smenu -d -n 0 -l -F -s /"QUIT$" -D o:0 n:2 i:1 d:" " \
                   -E'/^-$/ /' -e '^-$' < menu1)
    
      read ENTRY DUMMY <<< $LINE
    
      case $ENTRY in
        [1-4]) echo "The menu entry $ENTRY has been selected"
               ;;
        0)     ;;
      esac
    done
    
    exit 0

    The result:

    images/ex-menu1-sub.gif

  • Examples 2

    The same, but horizontal this time. The only difference with the previous example is the smenu call with different options.

    $ cat menu2.sh

    #!/bin/sh
    . . . . . . . . . . . . . . . . . . . . . . . . . . .
    
    LINE=$(smenu -d -n 0 -l -F -D o:0 n:2 i:1 d:" "    \
                 -1 Exit -e '^-$' -E'/^-$/ /' -e '^-$' \
               < menu2)
    . . . . . . . . . . . . . . . . . . . . . . . . . . .
    exit 0

    The result:

    images/ex-menu2-sub.gif

  • Example 3

    Now a matrix version.

    $ cat menu3

    " 1 Item 1" " 2 Item 2"
    " 3 Item 3" " 4 Item 4"
    -
    " 0 Exit"
    

    $ cat menu3.sh

    #!/bin/sh
    . . . . . . . . . . . . . . . . . . . . . . . . . . .
    
    LINE=$(smenu -d -n 0 -c -F -D o:0 n:2 i:1 d:" "    \
                 -1 Exit -e '^-$' -E'/^-$/ /' -e '^-$' \
               < menu3)
    . . . . . . . . . . . . . . . . . . . . . . . . . . .
    exit 0

    The result:

    images/ex-menu3-sub.gif

To restart the animations, refresh the page (shift refresh on Netscape based browsers).