Quantcast
Channel: how to source csh script from bash environment? - Ask Ubuntu
Viewing all articles
Browse latest Browse all 4

Answer by Sergiy Kolodyazhnyy for how to source csh script from bash environment?

$
0
0

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.


Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>