How to run csh script from sh script

I was wondering if there is a way to generate a csh script from a sh script. The following is an example of what it is trying to implement:

script1.sh:

#!/bin/sh

source script2

Script2:

#!/bin/csh -f

setenv TEST 1234
set path = /home/user/sandbox

When I run sh script1.sh, I get syntax errors generated from script2 (expected since we are using another Shebang). Is there a way to run script2 through script1?

+4
source share
5 answers

Instead, source script2run it like:

csh -f script2
+5
source

Since your use case depends on saving the environment variables specified by the cshscript parameter , try adding this to the beginning script1:

#!/bin/sh

if [ "$csh_executed" -ne 1 ]; then
    csh_executed=1 exec csh -c "source script2;
                                exec /bin/sh \"$0\" \"\$argv\"" "$@"
fi

# rest of script1

csh_executed ​​ 1 , csh script, script2, sh, , script2. exec , , "" . csh_executed csh , , script1 csh.


, , , , , , csh: script1 , .

+2

source ; script , . , sh- - , sh script.

script , :

script2
+1

script , script - exec. exec . source, , exec -ed , . , :

#!/bin/sh

exec /path/to/csh/script

:

#!/bin/sh

exec /path/to/csh/script
some-other-command

, , script? , :

#!/bin/sh

csh -f /path/to/csh/script
some-other-command
0

, csh script sh script, .

, , ( ) . csh script, , script; , .

csh script sh script, source . sh script.

csh script:

#!/bin/csh -f

setenv TEST 1234
set path = /home/user/sandbox

:

export TEST=1234
export PATH=/home/user/sandbox

(csh $path , $path. sh , $path.)

, script, , #! , ; .

script, source d csh tcsh, - source d . ed sh/ksh/bash/zsh script, , . , script sh, ; -

eval `./foo.csh`

( ).

csh script, , ; , , .

, , , , setup.sh setup.csh, sh/ksh/bash/zsh :

. /path/to/package/setup.sh

csh/tcsh :

source /path/to/package/setup.csh

, :

set path = /home/user/sandbox

script, , . $path , , , ls, . - :

set path = ( $path /home/user/sandbox )

, sh:

PATH=$PATH:/home/user/sandbox
0
source

Source: https://habr.com/ru/post/1524137/


All Articles