Adding to a menu


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Adding to a menu
# 8  
Old 11-13-2014
Thank you all Smilie
# 9  
Old 11-13-2014
My old favorite using select and an array:
Code:
#!/bin/bash
# select menu with array example
# 2014.11.13 by sea
################### 
#
#	Variables
#
	ar_menu=( "Menu entry 1" "Menu entry 2" "Menu entry 3" "Menu entry 4" )
#
#	Display & Action
#
	echo "Please select your action:"
	select menu in Back "${ar_menu[@]}";do
		echo "Selected: $menu"
		case "$menu" in
		Back)			break			;;
		"${ar_menu[0]}")	echo "menu action 1"	;;
		"${ar_menu[1]}")	echo "menu action 2"	;;
		"${ar_menu[2]}")	echo "menu action 3"	;;
		"${ar_menu[3]}")	echo "menu action 4"	;;
		esac
		echo "Press [ENTER] to see the menu:"
	done

Hope this helps to get started

EDIT:
Which modified could look like:
Code:
#!/bin/bash 
#
#	Variables
#
	ar_menu=( "Match patient" "Sanger analysis" ) 
#
#	Display & Action
#
	echo "Please select your action:"
	select menu in Back "${ar_menu[@]}";do
		echo "Selected: $menu"
		case "$menu" in
		Back)			break					;;
		"${ar_menu[0]}")	echo "Function to look up patient"	;;
		"${ar_menu[1]}")	echo "Do the sanger analyisis"		;;
		*)			echo "Invalid choice!!"			;;
		esac
		printf '%s\n' "-------------------" "Press [ENTER] to see the menu:"
	done

And would output like:
Code:
sh 1.sh 
Please select your action:
1) Back
2) Match patient
3) Sanger analysis
#? 2
Selected: Match patient
Function to look up patient
-------------------
Press [ENTER] to see the menu:
#? 3
Selected: Sanger analysis
Do the sanger analyisis
-------------------
Press [ENTER] to see the menu:
#? 4
Selected: 
Invalid choice!!
-------------------
Press [ENTER] to see the menu:
#? 1
Selected: Back


Last edited by sea; 11-13-2014 at 04:27 PM..
This User Gave Thanks to sea 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