简体   繁体   中英

using ksh shebang in a bash script

We will perform a migration from unix to Linux. the typeset -L only works with ksh

I created the following file:

#!/bin/ksh -u

echo $SHELL
typeset -L21 RUN_LOGL="LOG_FILE    "

Normally the shebang should indicate the correct interpreter (ksh). But when I call the script in a bash way:

$ . test.ksh

The output is:

/bin/bash

-bash: typeset: -L: invalid option

typeset: usage: typeset [-aAfFilrtux] [-p] name[=value] ...

the script is interpreter in bash way , and typeset -L is not accepted. whereas if I simply call

$test.ksh

it runs fine.

Is the way we call the script (bash way or ksh way) important enough to ignore the shebang ?

Thank you in advance.

. test.ksh

Does not execute the script. It is sourcing the script.

Sourcing a script always ignores the shebang. The shebang is only used when the script is executed like:

chmod +x test.ksh
./test.ksh

The shebang is only used if the interpreter was not defined previously, eg:

sh myScript.sh

will always invoke your sh , and ignores the shebang.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM