Reputation: 20384
I'm retrieving a list of items using CURL in this format into a file:
USA, Colorado, Denver
USA, Colorado, Denver (LOC1 S3)
USA, Florida
USA, Florida (LOC1 S2)
I need to show that list in a dialog (e.g. using Zenity) and pick one line to then use it as variable in a command e.g.
selloc = *prompt here*
dosomething "$selloc"
which would execute
dosomething "USA, Colorado, Denver (LOC1 S3)"
How can I do that?
Upvotes: 0
Views: 1283
Reputation: 1
#!/bin/sh
mapfile -t bravo < alpha.txt
select charlie in "${bravo[@]}"
do
break
done
echo "$charlie"
Output:
1) USA, Colorado, Denver 3) USA, Florida
2) USA, Colorado, Denver (LOC1 S3) 4) USA, Florida (LOC1 S2)
#? 2
USA, Colorado, Denver (LOC1 S3)
Upvotes: 2
Reputation: 189327
http://linux.byexamples.com/archives/265/a-complete-zenity-dialog-examples-2/ has examples of how to display "radio list" or "checkbox list" dialogs with Zenity.
selloc=$(zenity --list --text "Pick a Location" --radiolist \
--column "Pick" --column "Location" \
TRUE "USA, Colorado, Denver" \
FALSE "USA, Colorado, Denver (LOC1 S3)" \
FALSE "USA, Florida" \
FALSE "USA, Florida (LOC1 S2)"
dosomething "$selloc"
Obtaining the list of options from a file should be doable with xargs
or eval
.
selloc=$(eval zenity --list --text \"Pick a Location\" --radiolist \
--column \"\" --column Location $(curl -s http://example.com/list.txt |
sed 's/.*/FALSE "&"/;1s/^FALSE /TRUE /'))
Upvotes: 1