[csh] How to capture output from a command and pass it on to a variable?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [csh] How to capture output from a command and pass it on to a variable?
# 1  
Old 05-11-2008
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  
Old 05-11-2008
try using the backtick `
listfiles=`ls *.aaa`
# 3  
Old 05-11-2008
have you tried:
Code:
set listoffiles = '*.aaa'
echo $listoffiles

# 4  
Old 05-11-2008
I can't believe that! Smilie

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!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to read the output of a command line by line and pass it as a variable?

Hi, I have some 2000 names in a table like below. Java Oracle/SQL ANSI SQL SQL,DWH,DB DB&Java And by using for loop in my code i am able to get a single word but if there is any special character or space then it is considering as a next line. I have to execute the below queries in... (10 Replies)
Discussion started by: Samah
10 Replies

2. Homework & Coursework Questions

How to Dynamically Pass Parameter to plsql Function & Capture its Output Value in a Shell Variable?

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: 2. Relevant commands, code, scripts, algorithms: #! /bin/ksh v="ORG_ID" ... (2 Replies)
Discussion started by: sujitdas2104
2 Replies

3. Shell Programming and Scripting

How to capture system() function output in variable

How to capture system() function output in awk variable and the print that awk variable..... (8 Replies)
Discussion started by: bharat1211
8 Replies

4. UNIX for Dummies Questions & Answers

Capture Multiple Lines Into Variable As Of Standard Output

Hello All, I have the below script and output. cat test.sh #!/bin/bash -x logit() { echo " - ${*}" > ${LOG_FILE} } LOG_FILE=/home/infrmtca/bin/findtest.log VAR=`find . -type f -name "*sql"` logit $VAR Output: cat /home/infrmtca/bin/findtest.log -... (9 Replies)
Discussion started by: Ariean
9 Replies

5. Shell Programming and Scripting

cannot pass a echo output to a variable in bash

Hi, I have a problem with passing a echo output into a variable in bash file='1990.tar' NAME='echo $file | cut -d '.' -f1'; echo $NAME the result is echo $file | cut -d . -f1 however with this one,#!/bin/bash file='1990.tar' echo $file | cut -d '.' -f1 the result is what I... (2 Replies)
Discussion started by: 1988PF
2 Replies

6. Solaris

How to capture Output of truus command

Hi I want to check if some process is sleeping. I can see that in truss -p <pid> I want to capture output and check that output if proces sis sleeping. Please suggest way to capture output of truss command or other way to check if process is sleeping (1 Reply)
Discussion started by: ankush_mehra
1 Replies

7. Programming

capture the output of printf into another variable

Hi , I wonder if in java I can pipe the below output of the printf into a variable: System.out.printf(" This is a test %s\n", myVariable); I want to keep the output of the printf command to create my history array. Thanks. (2 Replies)
Discussion started by: arizah
2 Replies

8. Shell Programming and Scripting

Enter the command to capture output--help

&& echo "PLEASE enter the command to capture output" || echo "Processing your command manual" x=$# echo $x while do while man $@ | read -r line do >$@.txt ... (1 Reply)
Discussion started by: rrd1986
1 Replies

9. Shell Programming and Scripting

How to pass enviroment variable from csh to Informix sql script

Hello, I have a csh script that creates an environment variable. I want to pass the environment variable(CURR_TABLE_DATE) to an Informix sql script. Here is the csh: #!/bin/csh -f setenv INFORMIXSERVER market3_tcp setenv CURR_TABLE_DATE 20090714 set DATABASE = gm_cdr set SQL_DIR =... (0 Replies)
Discussion started by: jwoj
0 Replies

10. Shell Programming and Scripting

Pass csh variable to Perl

Hi All, I am trying to put the csh variable into a perl. In the below case, i am trying to put the csh variable "var" into my perl code. I tried to use '"$var"' but i don;t think it works. Can anybody help me pls? #!/bin/csh set var = `echo "xxx"` perl myperlcode.pl file ... (9 Replies)
Discussion started by: Raynon
9 Replies
Login or Register to Ask a Question