weird csh problem

kellywestbrooks

Registered
oh unix gurus, answer me this:

i have a 2-line csh script that reads as follows:

---<<BEGIN CODE>>---

#!/bin/csh

set line = $<
echo $line

---<<END CODE>>---

the file is saved as "line.csh"

when i execute the file from the command line:

[hostname] # ./test.csh

and i give it the line "hello world!" for input, it echos back to me:

hello

apparently, the "set line = $<" only stores the first word you type in into the variable line....shouldn't it store the entire line? i run this same script on solaris, and it spits back the entire input line....

...please explain
 
The only thing I can think of is that macosx doesn't truly have csh running... they use tcsh instead, whereas your solaris box probably does have REAL csh running.

While tcsh is a superset of csh, I am sure there are some minor differences in the way they handle arguments.

That being said, if you are going to do any real shell scripting, you should probably stick with bourne shell scripting... it is much more the norm, and you will be able to find more help on that subject. sh, bash, zsh, ksh are all capable of running bourne shell scripts out of the box while only tcsh and csh can run csh scripts...

Granted, its all personal preference, but in the long run I think you will have more success with sh scripts vs csh scripts.
 
thanks for your reply.

actually, i tried running the same script using csh, NOT tcsh (by changing the Terminal prefs), but got the same result.

running bourne shell is not an option for me; the reason that i am doing csh scripting is for a college class in csh scripting.

i searched everywhere on the internet i could about csh, suspecting that i had to change a flag or something to make it work, but found nothing. I am truly starting to suspect that this is a bug or something....

I am curious if EVERYONE gets the same result, or if its just my machine....
 
go find your tcsh and csh executables... are they the same size... if so then they are one in the same shell that has been renamed or symbolically linked. While I am not positive about this, I think that macosx only has tcsh on it and the csh is merely a copy or symbolic link to the tcsh... hence the same results.
 
The only reason that you're not getting what you want is that you haven't quoted the $< value. Try this:

#!/bin/csh

echo -n "Enter a few words: "
set input1=$<
echo -n "and a few more words: "
set input2="$<"

echo "First input = $input1"
echo "Second input = $input2"

exit 0


:)
 
Back
Top