Whiptail menu, getting back the variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Whiptail menu, getting back the variable
# 1  
Old 08-16-2012
Whiptail menu, getting back the variable

Hi all

Only learning so if any mistakes, let me know

I am trying to create a menu box with Whiptail, taking in the variables from a txt.file called Name.txt which has just 4 names listed for now, one below each other..ie

Dave
John
Mike
Mary

Bash script is below and calls the txt file above

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


Code:
#! /bin/bash
saveIFS="$IFS"
IFS=$'\n'
array=($(<Name.txt))
IFS="$saveIFS"
echo ""
 
for i in "${array[@]}"; do echo "$i"; done # iterate over the array
echo "These are my Varibles above " 
echo "" 
#This is where the Wiptail script comes in..passing in the array ${array[@]}
whiptail --backtitle "Hi" --title "These are the names" --menu "Please select the name you like" 14 40 6 "${array[@]}"
#This shows exit status
exitstatus=$?
if [ $exitstatus = 0 ]; then
echo "User selected Ok and entered " 
 
#This is where I would like to echo out the value selected
#echo value
else
echo "User selected Cancel."
fi

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

I am trying to catch the selection that was selected for the next part of a script but cant seem to do this
Also when I run the Wiptail menu, it shows 2 names on each line. I had been hoping to have it listed one below the other

ie
Dave John
Mike Mary

Any help would be great and thanks again

Moderator's Comments:
Mod Comment Please view this code tag video for how to use code tags when posting code and data.

Last edited by Corona688; 08-16-2012 at 01:23 PM..
# 2  
Old 08-16-2012
Well, does whiptail return the value to you? In what way does it do so?
# 3  
Old 08-16-2012
Hi Corona688

Whiptail did show me a value but just before the curser..and could not call it

But just now, if I enclose the whiptail command
Code:
activeNAME=$(whiptail --backtitle "Hi" --title "These are the names" --menu "Please select the name you like" 206010 "${array[@]}"3>&1 1>&2 2>&3)


and then echo this varible
Code:
 
echo $activeNAME

It works great, and shows me the name I called..so 90% there Smilie

Only thing left, is it displays 2 options, the names are shown as
Dave John
Mike Mary


And would like it displayed as 4 seperate options
Dave
John
Mike
Mary

Regards
Dan


PS ...Thanks for the heads up on the coding box
# 4  
Old 08-16-2012
What's the content of your name.txt?
# 5  
Old 08-16-2012
Hi

Its just the 4 names

Code:
Dave
John
Mike
Mary

Script calls it fine..but puts 2 names on each line when the Wiptail menu is used..so basically just 2 options instead of 4
# 6  
Old 08-16-2012
How does it respond to
Code:
Dave\n
John\n
Mike\n
Mary

This User Gave Thanks to Corona688 For This Post:
# 7  
Old 08-16-2012
it comes back with the following in the menu

Dave\n John\n
Mike\n Mary

Im afraid
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing positioning array as whiptail -- menu option

I may have asked this before, so forgive OF. Problem: I can pass positioning array as -- menu option to whiptail, but it does not show in the whiptail form as an array - only single (first member "lsusb" ) entry / line shows up. Code: DynamicEntry=$(whiptail \ --title "DEBUG... (1 Reply)
Discussion started by: annacreek
1 Replies

2. Shell Programming and Scripting

Redirecting stdout output to whiptail menu box

As a result of whiptail menu option I am getting a data from a file. Naturally it is output to terminal as stdour. I like to redirect the output back to the menu. It can be done with single input of line of text , see attached. I just cannot see where or how the sample... (0 Replies)
Discussion started by: annacreek
0 Replies

3. Shell Programming and Scripting

Bash Script - Whiptail Menu Help!

Hello, Been trying to build a menu with whiptail lately. However, my code doesn't seems to be working even though when i compared to other similar code they looks the same. #!/bin/bash clear whiptail --msgbox "Entering networking sub-menu" 20 78 whiptail --title Networking --menu... (8 Replies)
Discussion started by: malfolozy
8 Replies

4. UNIX for Dummies Questions & Answers

Pass value back to unix variable

i had this unix korn shell code that connects to oracle database and execute the oracle procedure. i need to add a variable that indicates the oracle procedure failed. basically the variable is to check if the oracle procedure failed it will assign 1 and when the variable is equal to 1 it will not... (4 Replies)
Discussion started by: wtolentino
4 Replies

5. Shell Programming and Scripting

Passing variable to Expression in back ticks.

Hi, In my perl script I want to check whether *.csv files exist and take the count . Below is the code: $path = “/home/usr/jan/myfiles” my $File_Count = `ls *.csv | wc -l `; # Checks in the current directory #Works fine if files exists. my $File_Count = `ls $path/*.csv | wc -l `; # I need... (2 Replies)
Discussion started by: jisha
2 Replies

6. UNIX for Dummies Questions & Answers

Input A Menu Selection In A Variable

hey all, me again....having a problem with my code, where I essentially am trying to show a menu, have the user select an option (from 1 to 5), then display which selection they picked... #!/bin/bash # A LIST OF THE ERROR MESSAGES AND THE PROPER SYNTAX: error_0="Correct amount of... (1 Reply)
Discussion started by: SoVi3t
1 Replies

7. UNIX for Dummies Questions & Answers

How Do I Create A Multi Line Menu Variable?

I want something that would show up basically like: Menu ----- 1) Option 1 2) Option 2 3) Option 3 Pick one: I tried menu = " Menu \r\n ----- \r\n 1)Option 1 \r\n..............etc etc etc" but that didnt work (just got the whole menu one one line, with the... (2 Replies)
Discussion started by: SoVi3t
2 Replies

8. Shell Programming and Scripting

Variable sub-menu issue

The code im having problems with is highlighted in red, upon selecting option 2 on the main menu (highlighted green) my echo "NETWORK CONNECTIVITY" command seems to get overlooked and the resulting output is "Thank you for using the Operator Administrative Tool." being displayed. Can anyone tell me... (2 Replies)
Discussion started by: warlock129
2 Replies

9. UNIX for Dummies Questions & Answers

Using a list menu as a variable

Hi again I have the follwing - cat ~/ABCFILE | grep "$SYSTEM" | grep "$USERNAME" What I'm looking to do is have the variable for $SYSTEM determined by the user making a selection from a numbered list. So, input 1 would be system ABC etc. I'm very puzzled as to how to go about this? Any... (3 Replies)
Discussion started by: Great Uncle Kip
3 Replies

10. Shell Programming and Scripting

Is it possible to pass variable from awk to shell back

I am passing a varaible to from Shell to awk then I am doing some maniplation for that variable inside awk. I want that maniplated variable value back to shell , Is this possible .Please let me know. (12 Replies)
Discussion started by: unishiva
12 Replies
Login or Register to Ask a Question