Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using ksh shebang in a bash script

Tags:

bash

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.

like image 801
Topas Avatar asked Jul 24 '26 21:07

Topas


1 Answers

. 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
like image 124
Ignacio Vazquez-Abrams Avatar answered Jul 27 '26 14:07

Ignacio Vazquez-Abrams