Select ksh menu question

I am creating a Select menu with a few options and I would like to create a "better" looking interface than just this:

1) Option 1
2) Option 2
3) Option 3

Instead, I would like something like this:

***********

  • Cool Script *
  • 1) Option 1 *
  • 2) Option 2 *
  • 3) Option 3 *
    ************

Can I do this with Select or do I have to use tput or something else? Below is a snippet of my script so far...

PS3="$main_menu_prompt"
select cmd in "Option 1" "Option 2" "Option 3"
do
        case $cmd in
                "Option 1")
                        clear
                        PS3="$submenu_prompt"
                        select option in "Yes" "No"
                        do
                                case $option in
                                        "Yes") print "**Not configured**"
                                               sleep 2
                                               break;;
                                        "No")  break;;
                                        *) print "You must enter a valid response!"
                                               sleep 2
                                               clear
                                               submenu;;
                                esac
                        done
                        clear
                        mainmenu
                        PS3=$main_menu_prompt;;

I predefined the PS3 prompts since I use them frequently in the script and I wanted the menu to appear everytime the user needed to provide input (to remind them what they are inputing for). I tried redirecting the screen output of the Select line to /dev/null, but ksh has an issue with the ">".

I googled for an answer/hint but I did not have any luck.

Thank you for any help.

You could come up with your own system. Ask the google, I have seen many menuing systems folks have come up with. Here's a fairly simple one:

#!/bin/ksh

typeset -r SLEEPTIME=2

REVON=$(tput smso)  # Reverse on.
REVOFF=$(tput rmso) # Reverse off.

while :
do
    clear
    print "\t    $REVON One way to do a menu $REVOFF"
    print
    print
    print "\tOptions:"
    print "\t---------------------------------------------"
    print "\t1) Option 1     4) Option 4"
    print "\t2) Option 2     5) Option 5"
    print "\t3) Option 3     6) Option 6"
    print
    print "\n\tOther Options:"
    print "\t----------------"
    print "\tr) Refresh screen"
    print "\tq) Quit"
    print
    print "\tEnter your selection: r\b\c"
    read selection
    if [[ -z "$selection" ]]
        then selection=r
    fi

    case $selection in
        1)  print "\nYou selected option 1"
            sleep $SLEEPTIME
            ;;
        2)  print "You selected option 2"
            sleep $SLEEPTIME
            ;;
        3)  print "You selected option 3"
            sleep $SLEEPTIME
            ;;
        4)  print "You selected option 4"
            sleep $SLEEPTIME
            ;;
        5)  ;&  #  Fall through example.
        6)  print "You selected option 5 or 6"
            sleep $SLEEPTIME
            ;;
      r|R)  continue
            ;;
      q|Q)  print
            exit
            ;;
        *)  print "\n$REVON Invalid selection $REVOFF"
            sleep 1
            ;;
    esac
done

Looks like this:

        One way to do a menu


        Options:
        ---------------------------------------------
        1) Option 1     4) Option 4
        2) Option 2     5) Option 5
        3) Option 3     6) Option 6


        Other Options:
        ----------------
        r) Refresh screen
        q) Quit

        Enter your selection: q

$
1 Like

Hi,

You can try the Curses Command Frontend (CCFE), a nice tool
to create menus to call shell scripts or commands.
It's curses based, so you can select items by moving a
cursor using arrow keys.
You can also add a form to ask user for input parameters and options
requested by selected script.