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

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

#! /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

Well, does whiptail return the value to you? In what way does it do so?

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

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

 
echo $activeNAME

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

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

What's the content of your name.txt?

Hi

Its just the 4 names

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

How does it respond to

Dave\n
John\n
Mike\n
Mary
1 Like

it comes back with the following in the menu

Dave\n John\n
Mike\n Mary

Im afraid

whiptail menu prints out pairs:

tag item
tag item
tag item

on return, the selected tag is printed to stderr. Don't know if the triple redirection above will do. In your names file, try to use two field entries like 1 Dave 2 John ... etc.

1 Like

Hi RudiC
Thats great..Thanks

Just padded it out with another Word and got back what I needed

Cheers