piping ls to zenity and returning selection to variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting piping ls to zenity and returning selection to variable
# 1  
Old 11-18-2009
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':

Code:
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
# 2  
Old 11-18-2009

Use command substitution:

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

This User Gave Thanks to cfajohnson For This Post:
# 3  
Old 11-18-2009
Yeah that works fine. Thanks.

Should have thought of that earlier since I tried:
Code:
x=(ls|sort|zenity --list --title="whatever" --column="thing")

Was only missing the $

Ah well. Thanks again.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Php assign selection to a variable

can someone help me assign the selection of a drop down menu to a variable? the variable i need to store the selection in is inputA. <form name="inputA"> <p align="center"> <p align="center">Name: <input name="inputA" type="text" size="45"> <select> <?php if ($handle =... (1 Reply)
Discussion started by: SkySmart
1 Replies

2. Shell Programming and Scripting

Need help piping a value to a variable

Hey Guys. Below is the code I am using to pipe a value into a variable. When I tried it says the following xargs: :HEX:: No such file or directory Not sure what it means. Can anyone please help me figure this out. Below is the code I am using. (It echo's out just fine) sed -n... (1 Reply)
Discussion started by: eldan88
1 Replies

3. Shell Programming and Scripting

Passing variable and returning

1. I setup a website on html with a single text box and a submit button. 2. When the user enters the data into the text box and clicks submit - The output is displayed on a php site I setup as well *Clearly I don't know much of PHP or HTML* So now, I want to.... take this output, convert it... (1 Reply)
Discussion started by: svalenciatech
1 Replies

4. Shell Programming and Scripting

Piping Unix Variable Array values into AWK

#ksh Here is my code: ERRORLIST="43032 12001 12002 12003 12004 34019 49015 49016 49017 49018 49024 49025 49026 58004 72003 12005 12006 12007 12008 12011 12012 16024 16023" for ERROR in ${ERRORLIST} do awk -v l="$lastdate" '/^....-..-../&&$0>l{d=$0}d&&/Error: '"${ERROR}"'/{print... (3 Replies)
Discussion started by: k1ko
3 Replies

5. UNIX for Dummies Questions & Answers

Input A Menu Selection In A Variable

hey all, me again....having a problem with my code, where I essentially am trying to show a menu, have the user select an option (from 1 to 5), then display which selection they picked... #!/bin/bash # A LIST OF THE ERROR MESSAGES AND THE PROPER SYNTAX: error_0="Correct amount of... (1 Reply)
Discussion started by: SoVi3t
1 Replies

6. UNIX for Dummies Questions & Answers

Loop on array variable returning error: 0 not found

I'm guessing i have a syntax error. I'm not sure it get's past the the while condition. I get an error 0 not found. Simple loop not sure what I'm doing wrong. #!/usr/bin/ksh set -A MtPtArray /u03 /u06 tUbound=${#MtPtArray } echo $tUbound i=0 while ($i -lt $tUbound) do print... (4 Replies)
Discussion started by: KME
4 Replies

7. Shell Programming and Scripting

Piping and assigning output to a variable in Perl

Hi All, I am trying to convert the below Csh code into Perl. But i have the following error. Can any expert help ? Error: ls: *tac: No such file or directory Csh set $ST_file = `ls -rt *$testid*st*|tail -1`; Perl my $ST_file = `ls -rt *$testid*st*|tail -1`; (10 Replies)
Discussion started by: Raynon
10 Replies

8. Shell Programming and Scripting

Variable Selection Operation Error

Ok i have taken your advised indented my code and i have managed to fix my problem but unfortuantely now another small one has arisen. The problem is that executing my commands requires two presses of the ENTER key as opposed to the originally being pressed once as one would expect, for example... (1 Reply)
Discussion started by: warlock129
1 Replies

9. Shell Programming and Scripting

piping output from PHP file into variable

Hi. I have a script like so: #!/bin/bash download='php /var/www/last.php' echo $download if $downloadHow do I pipe the output of the php file into a variable, as when i run the if statement, it just echos the file output to the screen and does not actually consider the output (it will be... (2 Replies)
Discussion started by: daydreamer
2 Replies

10. Shell Programming and Scripting

Piping to a file and setting filename using a variable

Hi all, I would like to send the output of a line in a ksh script to a file, but I need to name the file using a predefined variable: ls -l > $MYVAR.arc But what is the correct syntax for achieving this? I can't seem to find the correct syntax for giving the file an extension. Any... (8 Replies)
Discussion started by: mandriver
8 Replies
Login or Register to Ask a Question