How to assign variables in a csh script and used them as arguments for that same script?
I post another answer because a comment is too short. Look at the following.
I have a script named /tmp/T.csh:
#!/bin/cshset a="blah"echo $a
- My shell is bash; I type
/tmp/T.csh
: result isblah
(csh executed the script). - Still in bash; I type
unset a; /tmp/T.csh $a
: result is the same. - Still in bash; I type
. /tmp/T.csh
: no result (bash executed the script). - I type
csh
; now I am in csh. - I type
/tmp/T.csh
: result isblah
(of course). - I type
/tmp/T.csh $a
: "a: Undefined variable" set a = something
/tmp/T.csh $a
: blahecho $a
: somethingunset a
echo $a
: "a: Undefined variable"
I replicated all you did; hope this helps.You get an error for what you wrote on the command line, not for the content of your script. Even a simple echo
, as you can see here above, gives an error if you on the command line refer to a variable which does not exist.