Visit Our UNIX and Linux User Community


Menu with sub-menu options


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Menu with sub-menu options
# 1  
Old 05-29-2012
Question 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.
Quote:
1) Take input from user and show list of files with that name.
1.1) Show the contents of file chosen by user from the list.
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.
I can implement this as a separate option. But I want to implement this under option 1.
Can this be happen? I tried using some but failed.

Here is how my script is working.
Code:
#!/usr/bin/ksh

script_menu() {
while :
       do
       clear
echo  some action here
read choice
case $choice in

1) 
some action as per choice;;
2)     
       return;;
3)
       exit;;
    esac 
 done
}

#Main Menu
while :
       do
       clear
       echo ----------------------------------------------------
       echo    ******************Main Menu******************
       echo ----------------------------------------------------
       echo Select a Choice
       echo [1] call sub menu
       echo [2] View Log Files
       echo [3] Exit
       echo ----------------------------------------------------
       echo Select choice {1-2}:
read choice
case $choice in
1)
       script_menu;;
2)     
       echo files; 
       echo Enter file name;
       read -r filename ; find "$filename"_*.* -type f ! -name ".*" 2>errorlog 
       echo Press Enter; 
       read x;;
2.1) Can I solve above question here, like this?

3)   
       exit;;
*) 
       echo Invalid Number
     esac
done

please provide me your valuable help.
Thanks,
# 2  
Old 05-29-2012
correct this and try -
Code:
read -r filename ; find $filename"_"*.* -type f ! -name ".*" 2>errorlog

# 3  
Old 05-29-2012
Quote:
Originally Posted by donadarsh
correct this and try -
Code:
read -r filename ; find $filename"_"*.* -type f ! -name ".*" 2>errorlog

Hi No problem with that command.
I want to implement separate option for showing the contents of file.
here is the scene:
1. User enter to view the log files.
2. Entered the menu number. Menu shows the list of files.
3. Now he wanna see the contents of a particular file.
4. There should be an option which make him capable to enter the file name, so that he can see the contents of file.
5. If he doesn't enter the file name. It should return back to menu. Without saying anything.

Hope I'm able to clear my requirement.
# 4  
Old 05-30-2012
Hiya, I am assuming you are looking to have a sub-menu under an option that will return back to the main menu when exited. This example from another post I replied to shows a way to set up a menu framework using nested select constructs to create the menus. Run it and see if you get some ideas.
Code:
$ cat xxx
#!/usr/bin/ksh

#  Set select construct prompts for each menu level.
typeset -r MAINPROMPT="Select a main option: "
typeset -r MANGOPROMPT="Select mango option: "

#  Loop main menu until user exits explicitly.
while :
do
  print "\nTop-level Menu Title Goes Here\n"
  PS3=$MAINPROMPT  # PS3 is the prompt for the select construct.

  select option in "mango (has a sub-menu)" tango rango exit
  do
    case $REPLY in   # REPLY is set by the select construct, and is the number of the selection.
      1) # mango (has a sub-menu)
         #  Loop mango menu until user exits explicitly.
         while :
         do
           print "\nmango sub-menu title\n"
           PS3=$MANGOPROMPT
           select option1 in add substract exit
           do
             case $REPLY in
               1) # add
                  print "\nYou picked [add]"
                  break  #  Breaks out of the select, back to the mango loop.
                  ;;
               2) # subtract
                  print "\nYou picked [subtract]"
                  break  #  Breaks out of the select, back to the mango loop.
                  ;;
               3) # exit
                  break 2  # Breaks out 2 levels, the select loop plus the mango while loop, back to the main loop.
                  ;;
               *) # always allow for the unexpected
                  print "\nUnknown mango operation [${REPLY}]"
                  break
                  ;;
             esac
           done
         done
         break
         ;;
      2) # tango
         ;&  # Fall through to #3
      3) #rango
         print "\nYou picked $option"
         break
         ;;
      4) # exit
         break 2  #  Break out 2 levels, out of the select and the main loop.
         ;;
      *) # Always code for the unexpected.
         print "\nUnknown option [${REPLY}]"
         break
         ;;
    esac
  done
done

exit 0
$


Previous Thread | Next Thread
Test Your Knowledge in Computers #985
Difficulty: Medium
386BSD and FreeBSD were both derived from BSD releases.
True or False?

10 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

How to include menu based options in Shell script?

Hi Friends, I have a menu based tool which requires input/option to proceed further. How to make a shell script ? eg: menu looks like Get_data.sh to continue (y/n) : Here I need to key in "y" to proceed. I want to prepare a script which should consider option y. (5 Replies)
Discussion started by: suresh3566
5 Replies

3. Shell Programming and Scripting

Automate the menu options using shell script

I have a menu option which will look as follows Select a menu option 1.change password 2.login as root user 3.show system version 4.quit Select> 1 please enter the new password: unix reenter the new password: unix press any key to enter (then displays again the menu options to enter the... (4 Replies)
Discussion started by: shivakumar6g
4 Replies

4. 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

5. Shell Programming and Scripting

Perl simple text menu with options

Hopefully I'm in the right place. Im new to the forums and linux! I'm looking to add a menu to my perl hangman game i have created. The menu will use user input for the desired option and then perform the operation indicated. I would like something along the lines of: Welcome to Hangman... (1 Reply)
Discussion started by: jahburmski
1 Replies

6. Windows & DOS: Issues & Discussions

Windows Advanced Options Menu

I dual boot between Windows XP and Linux Mint. I am trying to get the Windows Advanced Options Menu to show up. Normally you would press f8 to make this happen when your computer is booting. With a dual boot it makes it way more complicated. If you press f8 when your computer first starts it does... (3 Replies)
Discussion started by: cokedude
3 Replies

7. Homework & Coursework Questions

Menu Driven Shell Script which accepts1 to 5 options

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: 1) Write a Menu Driven Shell Script which accepts1 to 5 options and performs the following actions for... (1 Reply)
Discussion started by: vaghya
1 Replies

8. Shell Programming and Scripting

menu.lst, boot options?

Hi all, I would like to have some details on menu.lst!! the reason is ,if i am trying to add my own boot option where do i need to add it? is it in menu.lst only or elsewere(am referring to unix os) because i tried adding a unique boot option and it was not reflected when the system booted?... (8 Replies)
Discussion started by: wrapster
8 Replies

9. UNIX for Dummies Questions & Answers

Help needed with menu options

I'm programming a menu for an intro to unix class and am hung up on 2 required options. One has to exit from unix. The other has to get a command prompt by using one of the menu choices, then return to the menu via CTRL-D. below is my code #!/bin/ksh #Jimmy's happy menu mesg y msg="ON"... (2 Replies)
Discussion started by: sanitywonko
2 Replies

10. UNIX for Dummies Questions & Answers

changing root menu options on Redaht

Hello all, I would like to change the options on the root menu when I use the middle button on a three mouse buttom setting. I can append to the menu but, I seem to be unable to find the lisp code for pop-root-menu. Does anyone know how to change this? THANKS ALL (3 Replies)
Discussion started by: larry
3 Replies

Featured Tech Videos