nibalan has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to source a startup script which is cshell in perl. For that purpose I wrote a shell wrapper to source the startup script and run the script to system command as below:

submain.pl contains:

 system("sh sourcing.sh");

Sourcing.sh will have the following contents:

 source startup.csh

startup.csh will have:

setenv CC_LIBDIR ${CC_ROOTDIR}/lib/perl setenv CC_STARTUP_FILE ${CC_LIBDIR}/cc_startup.pm

When I tried executing the perl script by executing the command perl submain.pl I get the following error:

/nfs/scm-cctools/Releases/Alpha_Beta/7_3_0/start.csh: line 1: setenv: command not found

/nfs/scm-cctools/Releases/Alpha_Beta/7_3_0/start.csh: line 2: setenv: command not found

But if I try to source a bash script it would work fine. How can I source a csh script using system command in perl?

Replies are listed 'Best First'.
Re: invoking a cshell using system comand
by jethro (Monsignor) on Jul 14, 2011 at 12:06 UTC
    Why do you think sh would call the csh? AFAIK sh is either a bourne shell (i.e. the mother of csh,ksh...) or an alias to bash, neither has a setenv command. You could use 'csh' to invoke the cshell or use a shebang line in your script (#!/usr/bin/csh as first line) and just call the script (without any sh or csh before it)
      Thanks a ton. I am new to shell scripting and I thought executing a shell script is by giving sh <script name>. Thanks for your reply
Re: invoking a cshell using system comand
by osbosb (Monk) on Jul 14, 2011 at 14:46 UTC
    Your shell script is calling bash to execute your content.
    $ echo $SHELL /bin/bash $ setenv No command 'setenv' found, did you mean: Command 'netenv' from package 'netenv' (universe) setenv: command not found $ csh % setenv | tail -n 1 _=/bin/csh %
    In the header of your shell script you need to declare your executing shell - "#!/bin/csh " or where ever it is located on your system.
    $ cat test #!/bin/csh echo "trying to use setenv" setenv | tail -n 1 $ ./test trying to use setenv _=./test