Click to See Complete Forum and Search --> : Creating a Csh variable as a list


Usulsuspct
04-27-2001, 01:21 PM
I am working on a homework problem for a class of mine, and I am having a little trouble. We are working in the Csh, and have to write a sript that will take two arguements (directory names) and then create a sorted list of the contents of the directory's.

I thought that I would be able to store the names of the contents in a list variable but it isnt working quite as planned. This is what I thought I would do to store the contents of one of the directories in lists then compare the two lists and create a new sorted list of the values:

set list1 = ( '/bin/ls $argv[1]' )
set list2 = ( '/bin/ls $argv[2]' )

The above commands arent working for me. I was hoping the would store in the variables a listing of the dy's contents ie.

list1 = ( a.out temp.c fruit.b )

After I the set list commands I put in a simple echo $list1 command to see if it works and I get an error saying echo: no match

What do you guys thinkg? Is it possible to create a list in that manner? And if not, how would I go about doing this?

TheLinuxDuck
04-27-2001, 03:51 PM
One thing I noticed right off is that your set commands are using the single quotes, and not backticks, which will do the system call you're looking for.

I don't have a whole lot of experience with shell scripting, so I can't offer too much help. (^= But, one thing I can offer is that you can make the script work with unlimited dirs from the command line by doing something like:

#!/usr/bin/tcsh

set allPaths=""
foreach path ($*)
echo "Searching through $path..."
foreach item ($path/*)
echo " $item added..."
set allPaths="$allPaths $item"
end
echo "--Done with $path--"
end

echo "allPaths=$allPaths"
exit 0

When run..

brad@www2:~$ ./list2.sh /home/ftp
Searching through /home/ftp...
/home/ftp/bin added...
/home/ftp/etc added...
/home/ftp/incoming added...
/home/ftp/lib added...
/home/ftp/pub added...
/home/ftp/usr added...
/home/ftp/welcome.msg added...
--Done with /home/ftp--
allPaths= /home/ftp/bin /home/ftp/etc /home/ftp/incoming /home/ftp/lib /home/ftp
/pub /home/ftp/usr /home/ftp/welcome.msg

TheLinuxDuck
04-27-2001, 05:42 PM
When is the assignment due? I don't want to give you the answers, but I can help, as I have been studying up on tcsh lately..

Usulsuspct
04-27-2001, 09:21 PM
well the assignment is not ever due, but I have a test on Monday that I might need to know the concepts involved.

It was my understanding that single quotes ' ' would server as command substitution?

TheLinuxDuck
04-28-2001, 03:24 AM
Originally posted by Usulsuspct:
<STRONG>It was my understanding that single quotes ' ' would server as command substitution?</STRONG>

Not single quotes, backticks.. the `` and the '' make a big difference.. (^=

I can give you a great resource list on using the tcsh if you like..

And maybe even some tips on getting this done. (^=

Usulsuspct
04-28-2001, 03:44 AM
I would appreciate any help I can get........

Usulsuspct
04-28-2001, 05:10 PM
You are correct there is a big differencd between single quotes ' and backticks `

Thanks for the info