[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:

ls *.aaa

and put it into a variable "listoffiles".

What I tried was:

set listoffiles = 'ls *.aaa'
echo $listoffiles

and what I got echoed was:

$ ls file1.aaa file2.aaa file3.aaa

instead of

$ 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?

try using the backtick `
listfiles=`ls *.aaa`

have you tried:

set listoffiles = '*.aaa'
echo $listoffiles

I can't believe that! :eek:

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!