0

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?

2 Answers 2

2
#!/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)
Sign up to request clarification or add additional context in comments.

1 Comment

This has the obvious flaw that it doesn't have a GUI. The question was specifically about how to do this in e.g. Zenity.
1

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 /'))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.