Display user selction from bash menu


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Display user selction from bash menu
# 1  
Old 08-18-2016
Display user selction from bash menu

I am trying to display the text the user selects from a bash menu. The below will display the menu and allow the user to enter a number, but will not display the choice selected.

bash
Code:
while true
    do
        printf "\n please make a selection from the MENU \n
        ==================================
        \t 1  Incidental Findings
        \t 2  CHARGE Syndrome
        \t 3  PFS       
        ==================================\n\n"
        printf "\t Your choice: "; read menu_choice
        echo "$1"
done

So if the user selects 2 from the menu, then CHARGE Syndrome is displayed. Thank you Smilie.

Last edited by cmccabe; 08-18-2016 at 05:31 PM.. Reason: fixed format
# 2  
Old 08-18-2016
Assuming bash shell take a look at:-
help case
And search case exmples on here, there is a plethora of answers.
This User Gave Thanks to wisecracker For This Post:
# 3  
Old 08-18-2016
That's what the select statement in bash is for:
Code:
PS3="please make a selection from the MENU: "
select CH in "Incidental Findings" "CHARGE Syndrome" "PFS"
  do echo "Your choice: $CH"
  done

These 2 Users Gave Thanks to RudiC For This Post:
# 4  
Old 08-18-2016
It is possible to use an array index, too.

Code:
#!/bin/bash

CHOICES=("Incidental Findings" "CHARGE Syndrome" "PFS")

for ITEM in "${CHOICES[@]}";do
  ((i++))
  echo "$i $ITEM"
done
read -p "Your choice: " RESPONSE 
echo ${CHOICES[ $(( $RESPONSE - 1 )) ]}

"dialog" can do nice dialogs too...

Code:
dialog --menu Title 10 60 6 1 "Incidental Findings" 2 "CHARGE Syndrome" 3 "PFS"

---------- Post updated at 12:37 AM ---------- Previous update was at 12:04 AM ----------

Quote:
Originally Posted by RudiC
That's what the select statement in bash is for:
Code:
PS3="please make a selection from the MENU: "
select CH in "Incidental Findings" "CHARGE Syndrome" "PFS"
  do echo "Your choice: $CH"
  done

Nice one. Never used it before. Thanks.

Last edited by stomp; 08-18-2016 at 07:17 PM..
This User Gave Thanks to stomp For This Post:
# 5  
Old 08-20-2016
Thank you all Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash Menu using zenity

Hi, I'm new to bash, and have an example menu script using Zenity. It works fine if the user enters A B or C, but if the user enters nothing, I can only figure out how to exit the script. How do I get the menu to reappear if no input is selected? The script is: title="Select example"... (2 Replies)
Discussion started by: allen11
2 Replies

2. Open Source

Bash menu not running

The perl command is not executing? I am trying to run the .pl in my cygwin home directory (C:\cygwin\home\cmccabe) using ${id}.txt.hg19_multianno.txt (located in the annovar directory) as the input file to be formatted and $FILENAME is the output file to be saved. The .pl is attached as... (8 Replies)
Discussion started by: cmccabe
8 Replies

3. UNIX for Dummies Questions & Answers

Simple bash script menu

Dear Sir, May I know how do I go about adding the following feature into the script below: When user enter values other than 1,2,3,4, a) Message “Wrong entry !!! Pls select 1,2,3 or 4” is displayed b) The screen is cleared again and the menu is displayed. #!/bin/bash clear var=1... (2 Replies)
Discussion started by: fusetrips
2 Replies

4. Shell Programming and Scripting

get chosen value from bash menu

Hi again :) This is just a sample whiptail menu. Works great, but have been trying to get the chosen value into a variable but failing pretty bad...its ther but unsure how to echo it out when needed #! /bin/bash #This is the menu whiptail --title "Menu example" --menu "Choose an... (9 Replies)
Discussion started by: olearydc
9 Replies

5. Shell Programming and Scripting

Display a menu on bottom right of screen

Hi, I have a menu of around 10 lines with options. I want to display it in bottom right corner of screen for better display. I can do it with clear screen. But I don't want to use it, because it will clear the existing text. After one choice from menu is executed, the menu should just place... (3 Replies)
Discussion started by: som.nitk
3 Replies

6. Shell Programming and Scripting

Help regarding a bash menu script

Greetings all, I'm having some trouble writing a menu drive bash script, actually coding the menu part was not difficult however its a problem with a menu option I'm having trouble with. My menu has 5 options, when the user selects the second option, they are then prompted to enter a number from... (5 Replies)
Discussion started by: Vitrophyre
5 Replies

7. Shell Programming and Scripting

Menu / Log files - reading / display

So I'm pretty green still at this, and right now I don't even have the IF statements in just trying to get this part to work. I want to basically click optino 1,2,3,4 for which logs I want to search, and then be able to put in the variable I want to grep out? Sounds easy just not clear in my mind... (4 Replies)
Discussion started by: xgringo
4 Replies

8. Shell Programming and Scripting

Bash menu script

I have a main menu quit=n while do clear echo echo "1. General system information" echo "2. Hardware utilisation information" echo "3. File management" echo "4. User information" echo "5. Information on network connectivity" echo "6. Information on processes" echo "Q.Quit" ... (3 Replies)
Discussion started by: AngelFlesh
3 Replies

9. Shell Programming and Scripting

Presenting the user a menu in Bash ...

Hello, I am trying to write a bash script function to present the user a menu of options. The following is what I have so far: function MainMenu { while ] do echo "--------------------------------------------------------------------------------" echo... (4 Replies)
Discussion started by: ckoeber
4 Replies
Login or Register to Ask a Question