How to assign variables in a csh script and used them as arguments for that same script? How to assign variables in a csh script and used them as arguments for that same script? unix unix

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
  1. My shell is bash; I type /tmp/T.csh: result is blah (csh executed the script).
  2. Still in bash; I type unset a; /tmp/T.csh $a: result is the same.
  3. Still in bash; I type . /tmp/T.csh: no result (bash executed the script).
  4. I type csh; now I am in csh.
  5. I type /tmp/T.csh: result is blah (of course).
  6. I type /tmp/T.csh $a: "a: Undefined variable"
  7. set a = something
  8. /tmp/T.csh $a: blah
  9. echo $a: something
  10. unset a
  11. 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.


prompt> unset aprompt> ./T.csh 4773 XXXX.XX "$a"

The first command, "unset a", deletes the variable. In the second command you try to read the variable (on the command line!). That is why csh complains.