Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

Whiptail menu, getting back the variable

$
0
0
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:
Please view this code tag video for how to use code tags when posting code and data.

Viewing all articles
Browse latest Browse all 16232

Trending Articles