The shebang line already takes care of that for you. When you run a script that has #! /bin/csh -f
as first line, the system will recognize #!
part as script, and load whatever interpreter is specified after it (in this case /bin/csh
).
Alternatively, you could call the interpreter explicitly , with csh /path/to/script.csh
.
Here's a small demo. My interactive shell is mksh
and I am calling a simple csh
script:
xieerqi:
$ cat bin/whiledemo.csh
#! /bin/csh -f
# demoloop.csh - Sample loop script
set j = 1
while ( $j <= 5 )
echo "Welcome $j times"
@ j++
end
xieerqi:
$ echo $SHELL
/bin/mksh
xieerqi:
$ bin/whiledemo.csh
Welcome 1 times
Welcome 2 times
Welcome 3 times
Welcome 4 times
Welcome 5 times
xieerqi:
$ csh bin/whiledemo.csh
Welcome 1 times
Welcome 2 times
Welcome 3 times
Welcome 4 times
Welcome 5 times
Note that if you have even one space in front of #!
, the #!
won't be interpreted, hence the script will run with your interactive shell from which you call the script. Naturally, you can expect script to fail due to different syntax between script and what interactive shell expects. In the process of writing this answer, I encountered this exact error.