The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
ls command output to variable in script dsrookie UNIX for Dummies Questions & Answers 1 03-10-2008 12:14 PM
can I pass awk variable to system command? zhynxn Shell Programming and Scripting 2 07-05-2006 08:11 AM
Assigning output of command to a variable oma04 Shell Programming and Scripting 5 06-27-2006 09:11 AM
redirect command output to variable hugow UNIX for Dummies Questions & Answers 1 06-22-2005 03:43 AM
Command output to a variable. videsh77 Shell Programming and Scripting 8 12-16-2004 02:06 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-11-2008
Registered User
 

Join Date: May 2008
Posts: 2
Stumble this Post!
Question [csh] How to capture output from a command and pass it on to a variable?

Hi there!

I'm trying to write a script that will capture output from a command and assign it to a variable.

Let's say, for example, I'd like to catch from inside the script whatever the following command outputs:
Code:
ls *.aaa
and put it into a variable "listoffiles".

What I tried was:
Code:
set listoffiles = 'ls *.aaa'
echo $listoffiles
and what I got echoed was:
Code:
$ ls file1.aaa file2.aaa file3.aaa
instead of
Code:
$ file1.aaa file2.aaa file3.aaa
I played with this for a while trying various combinations and also looked into a few publications on scripting and couldn't find the solution. What am I doing wrong?
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-11-2008
JCR JCR is offline
Registered User
 

Join Date: Jan 2007
Posts: 29
Stumble this Post!
try using the backtick `
listfiles=`ls *.aaa`
Reply With Quote
  #3 (permalink)  
Old 05-11-2008
redhead's Avatar
Registered User
 

Join Date: Feb 2002
Location: Denmark
Posts: 48
Stumble this Post!
have you tried:
Code:
set listoffiles = '*.aaa'
echo $listoffiles
Reply With Quote
  #4 (permalink)  
Old 05-11-2008
Registered User
 

Join Date: May 2008
Posts: 2
Stumble this Post!
I can't believe that!

With the backtick it worked just fine!

I need to use the assignment with a different command, this was just an example.

Thank you both for your help!
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:36 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0