Adding to a menu


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Adding to a menu
# 1  
Old 11-13-2014
Adding to a menu

Code:
 menu() {
    clear
    printf "\n MENU \n\n
    ==================================\n\n\n
    \t 1  Match patient\n
	\t 2  Sanger analysis\n\n
    \t 3  Exit\n\n\n
    ==================================\n\n\n"

    printf "\t Your choice: "; read menu_choice

    case "$menu_choice" in
        1) match ;;
		2) sanger ;;
        3) printf "\n Bye! \n\n"; exit ;;
        *) printf "\n Invalid choice."; sleep 2; menu ;;
    esac
}

Code:
  MENU


    ==================================



         1  Match patient

                 2 Sanger analysis


         3  Exit

Trying to add menu items but it appears to be misaligned and II'm not sure why. Thank you Smilie.
# 2  
Old 11-13-2014
It's clearly misaligned in your source -- not too mysterious. Maybe your text editor and the terminal disagree on how many spaces a tab is.

The shell has a built in menu tool which may make your life simpler:

Code:
clear ; printf "%s\n" "MENU" "========================"

# This is not just a menu, it's a loop.  It keeps asking until you
# break out with 'break' or 'exit'.
select X in "Match patient" "Sanger analysis" "Exit"
do
        case "$REPLY" in
        1)      match  ;;
        2)      sanger ;;
        3)      exit   ;;
        esac

        clear ; printf "%s\n" "MENU" "========================"
done


Last edited by Corona688; 11-13-2014 at 03:23 PM..
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 11-13-2014
But - you have an extra <TAB> in your printf statement. What now is unclear?

How about creating the menu in a text file and catting that out before reading the choice?
This User Gave Thanks to RudiC For This Post:
# 4  
Old 11-13-2014
I guess RudiC is right.

Code:
    \t 2  Sanger analysis\n\n

I think you have two tab stops here infront of "\t". Try it with a single tab.

Alternatively delete the whole line containing menu option 2, copy the previous line and paste it in the (new) next (empty) line and replace the text.

Hope I made myself clear.
This User Gave Thanks to junior-helper For This Post:
# 5  
Old 11-13-2014
What about

Code:
 dialog

?

Regards,
xabbu
This User Gave Thanks to xabbu For This Post:
# 6  
Old 11-13-2014
Code:
$ dialog
-bash: dialog: command not found
$

select, on the other hand, is a built-in in most modern shells.
This User Gave Thanks to Corona688 For This Post:
# 7  
Old 11-13-2014
Quote:
Originally Posted by Corona688
Code:
$ dialog
-bash: dialog: command not found
$

select, on the other hand, is a built-in in most modern shells.
Yes, you are right.

Regards,
xabbu
This User Gave Thanks to xabbu For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

8 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. UNIX for Beginners Questions & Answers

Adding to an array in an external file, and adding elements to it.

I have an array in an external file, "array.txt", which contains: char *testarray={"Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"};I want to be able to add an element to this array, and have that element display, whenever I call it, without having to recompile... (29 Replies)
Discussion started by: ignatius
29 Replies

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

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

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

Adding new lines to a file + adding suffix to a pattern

I need some help with adding lines to file and substitute a pattern. Ok I have a file: #cat names.txt name: John Doe stationed: 1 name: Michael Sweets stationed: 41 . . . And would like to change it to: name: John Doe employed permanently stationed: 1-office (7 Replies)
Discussion started by: hemo21
7 Replies

7. Shell Programming and Scripting

Get a value from menu.

Hi, I have a shell-script (in bash) wich read from a file this: 1 Telediario 1 2009012609000 2 Mira quien baila 2009012511000 3 No mas 2009012603000 ..... ..... 12 Quiero ser tu 20090127113000 13 Al igual que 20090127130000 ........ (2 Replies)
Discussion started by: mierdatuti
2 Replies

8. Shell Programming and Scripting

Menu

How do i make a menu... I need to be able to select options that run scripts that i make. like displaying/adding/sorting/deleting records of a file. i have the displaying part down but I want to make the menu now then i'll figure out the deleting/adding/sorting. (5 Replies)
Discussion started by: space
5 Replies
Login or Register to Ask a Question