#!/bin/sh
#@(#) Example bash menu script (John S. Urban, Revised 20130113)
# Some unusual features:
#  o allows option names as well as numbers
#  o handles a ctrl-C
#  o allows system commands at the prompt, including cd(1)
export PATH
PATH=$PATH:`dirname $0`
#############################################
COMMAND1(){ # a function to execute if option 1 is selected
echo 'COMMAND1'
}
#############################################
COMMAND2(){ # a function to execute if option 2 is selected
echo 'COMMAND2'
}
#############################################
COMMAND3(){ # a function to execute if option 3 is selected
echo 'COMMAND3'
}
#############################################
HELP(){  # a function to execute when HELP is selected
cat <<\EOF
Put help text here
EOF
}
#############################################
ENTER(){
# prompt and read a value from screen
VAR=${1:-VALUE}
trap ':' 1 2 3 15
PROMPT="${2:-'Enter value'}"
while : ; do
   printf "$PROMPT":
   read VALUE
   [ "$VALUE" != ''  ] && break
   echo 'E-R-R-O-R: Enter non-blank value'
done
eval $VAR="'$VALUE'"
}
#ENTER VALUE1 'this is a prompt message'
#echo VALUE1 is $VALUE1
#############################################
OUCH(){
cat <<\EOF
Enter "q" to quit or enter command or menu option.
allowed abbreviations are in braces.
EOF
}
#############################################
trap "OUCH; exec $0" 1 2 3 15
PS3=`hostname`:
#############################################
NULL=
select SELECT_NAME in \
 'command one[one]' \
 'command two[two]' \
 'command three[three]' \
 'help[h]' \
 'quit[q]' \
$NULL
#############################################
do
   #echo "1: REPLY $REPLY SELECT_NAME $SELECT_NAME"
   SELECT_NAME=${SELECT_NAME:-$REPLY}
   #echo "2: REPLY $REPLY SELECT_NAME $SELECT_NAME"

#--------------------------------------------
case "$SELECT_NAME" in
#--------------------------------------------
'help[h]'|help|h|H)             HELP ;;
#--------------------------------------------
'quit[q]'|quit|q|Q)             break ;;
#--------------------------------------------
'command one[one]'|one|o)       COMMAND1 ;;
'command two[two]'|two|t)       COMMAND2 ;;
'command three[three]'|three|t) 
    ENTER NAME 'Enter value'
    echo "NAME is $NAME"
    COMMAND3
 ;;
#--------------------------------------------
# no match, try it as a command in current process
# so cd(1) and export SELECT_NAME=VALUE work
   *) eval $REPLY ;;
#--------------------------------------------
   esac
#############################################
done
#############################################
exit
#############################################
