piping ls to zenity and returning selection to variable

Hi

I'm fairly new to unix and scripting (in BASH) and am here to post my first question.

What I'm trying to do is pipe a sorted listing (ls) to zenity and when the list appears to the user, the choice they choose is returned to a variable so it can be used in conditional statements.

I can get the list to appear but not get the choice. Example i'm using below:

Say my PWD has directories/files 'one' and 'two':

ls|sort|zenity --list --title="whatever" --column="thing"

This will show 'one' and 'two' in a list, and when one is selected and ok pressed, the selection is echoed into the terminal. I want it to be stored in a variable instead.

Any ideas?

Thanks

Use command substitution:

x=$( ls|sort|zenity --list --title="whatever" --column="thing" )
1 Like

Yeah that works fine. Thanks.

Should have thought of that earlier since I tried:

x=(ls|sort|zenity --list --title="whatever" --column="thing")

Was only missing the $

Ah well. Thanks again.