Interactive menu


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Interactive menu
# 1  
Old 12-11-2007
Interactive menu

Hi ,some time ago i did an interactive menu based on eval function for navigation , one of the post remind me it. I think it could be handy for others.

Code:
#!/usr/bin/ksh

keyRead ()
{
tput smso
echo "Enter option."
tput rmso
oldstty=$(stty -g)
stty -icanon -echo min 1 time 1
Answer=$(dd bs=1 count=1 2>/dev/null)
stty "${oldstty}"
}


menu1()
{
#set -x
clear 
echo "MENU1"
echo "====="
echo "1-MENU11"
echo "2-MENU12"
echo "0-BACK"
keyRead
menu
}
menu11()
{
#set -x
clear 
echo "MENU11"
echo "====="
echo "0-BACK"
keyRead
menu
}
menu12()
{
clear 
echo "MENU12"
echo "====="
echo "0-BACK"
keyRead
menu
}
menu2()
{
clear 
echo "MENU2"
echo "====="
echo "0-BACK"
keyRead
menu
}
menu3()
{
clear 
echo "MENU3"
echo "====="
echo "1-MENU31"
echo "2-MENU32"
echo "0-BACK"
keyRead
menu
}
menu31()
{
clear 
echo "MENU31"
echo "====="
echo "1-MENU311"
echo "0-BACK"
keyRead
menu
}
menu311()
{
clear 
echo "MENU311"
echo "====="
echo "0-BACK"
keyRead
menu
}
menu312()
{
clear 
echo "MENU312"
echo "====="
echo "0-BACK"
keyRead
menu
}


menuExit ()
{
sufix=$(echo ${sufix}|awk '{printf("%s",substr($0,1,length-1))}')
current="menu${sufix}"
Answer=""
eval ${current}
}


menu ()
{
if [ "${Answer}." = "." ]
then
   clear
   echo "MAIN MENU"
   echo "=============="
   echo "1-MENU1"
   echo "2-MENU2"
   echo "3-MENU3"
   echo "0-BACK"
   keyRead
fi
while true
do
   case ${Answer} in
      0) if [ "${current}." = "menu." ]
         then
            exit 0
         else
            menuExit
         fi;;


      *) sufix="${sufix}${Answer}" 
         current="menu${sufix}"
         eval ${current} 2>/dev/null
         if [ $? -ne 0 ]
         then
            menuExit   
         fi;;
   esac
done
}


###################################################
#                     MAIN                        #
###################################################


Answer=""
oldstty=$(stty -g)
clear
current=menu
sufix=""
menu


exit 0

Regards.
This User Gave Thanks to Klashxx For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Gnome 3.28.3 menu item dissapears under the system menu

I installed CentOS 8 with Gnome 3.28.2 and I noticed that the "switch user" menu item disappeared from under the system menu of Gnome classic (Both X11 & Wayland). I checked google and this problem seems to have a history going back several releases of Gnome. Unfortunately, I never found a... (1 Reply)
Discussion started by: bodisha
1 Replies

2. Shell Programming and Scripting

Need help in create menu with 3 sub menu using the case command

hi all i am a newbie to this is there any examples on creating a main menu with 3 sub menu main menu -> option a , b and c a menu -> option 1 ,2 and 3 b menu -> option 1 ,2 c menu -> option 1 ,2 i am getting headache as my code kept getting unexpected EOF ---------- Post... (0 Replies)
Discussion started by: chercm
0 Replies

3. Shell Programming and Scripting

Menu with sub-menu options

Hi! I have created on script which is working fine with menu options and with a sub-menu. I want to enhance it by using sub-options under menu options. Like. option 1) will give the list only. option 1.1) should give the option to user to choose one file, whose content user wanna see. ... (3 Replies)
Discussion started by: sukhdip
3 Replies

4. Red Hat

Interactive PXE Boot Menu

I have been asked to modify our PXE server such that there will be only one entry in the pxelinux.cfg/default file, where the same kernel and initrd.img will be used regardless of what operating system is to be installed, and the user will type in the path to the kickstart file that will be used. ... (7 Replies)
Discussion started by: ceb
7 Replies

5. Shell Programming and Scripting

Menu in Menu script issue

Problem: I am trying to create a menu in a menu script and I am running into an issue with the calculator portion of the script. I am first presented with the ==Options Menu== which all 5 options working correctly. Now comes the fun part. I select option 1 which takes me to my ==Calculator... (1 Reply)
Discussion started by: iDdraig
1 Replies

6. Shell Programming and Scripting

Execute interactive bash menu script in browser with PHP

I have an interactive menu script written in bash and I would like use PHP to open the interactive bash menu in a browser. Is this possible? Using the sytem() function in php runs the script but it's all garbled. Seems like maybe a terminal window needs to be opened in php first? ... (1 Reply)
Discussion started by: nck
1 Replies

7. Homework & Coursework Questions

How to write script that behaves both in interactive and non interactive mode

Q. Write a script that behaves both in interactive and non interactive mode. When no arguments are supplied it picks up each C program from the directory and prints first 10 lines. It then prompts for deletion of the file. If user supplies arguments with the script , then it works on those files... (8 Replies)
Discussion started by: rits
8 Replies

8. Homework & Coursework Questions

Help with Interactive / Non Interactive Shell script

Q. Write a script that behaves both in interactive and non interactive mode. When no arguments are supplied it picks up each C program from the directory and prints first 10 lines. It then prompts for deletion of the file. If user supplies arguments with the script , then it works on those files... (1 Reply)
Discussion started by: rits
1 Replies

9. Shell Programming and Scripting

Interactive Array Menu

This should be simple, but i haven't done it before... KSH I am reading a file into an array and currently displaying the values to the screen. What I need to do is to display a subset of those values, likely numbered, and prompt the user to select one. When they enter the number, it... (2 Replies)
Discussion started by: gecko2424
2 Replies
Login or Register to Ask a Question