The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 04:14 PM
can I pass awk variable to system command? zhynxn Shell Programming and Scripting 2 07-05-2006 11:11 AM
Assigning output of command to a variable oma04 Shell Programming and Scripting 5 06-27-2006 12:11 PM
redirect command output to variable hugow UNIX for Dummies Questions & Answers 1 06-22-2005 06:43 AM
Command output to a variable. videsh77 Shell Programming and Scripting 8 12-16-2004 06:06 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-11-2008
machinogodzilla machinogodzilla is offline
Registered User
  
 

Join Date: May 2008
Posts: 9
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?
  #2 (permalink)  
Old 05-11-2008
JCR JCR is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 38
try using the backtick `
listfiles=`ls *.aaa`
  #3 (permalink)  
Old 05-11-2008
redhead's Avatar
redhead redhead is offline
Registered User
  
 

Join Date: Feb 2002
Location: Denmark
Posts: 67
have you tried:
Code:
set listoffiles = '*.aaa'
echo $listoffiles
  #4 (permalink)  
Old 05-11-2008
machinogodzilla machinogodzilla is offline
Registered User
  
 

Join Date: May 2008
Posts: 9
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!
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:12 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0