If the shell script is
But the value of my $SHELL is ksh.
Will it make a difference if I changed my ksh to sh, and then executed the script. ie. will a script have different behaviour depending on what type of shell is executing it.
will a script have different behaviour depending on what type of shell is executing it.
In the sense that
bash script.sh and
ksh script.sh are likely to behave differently, yes. Commonly, that difference will be that one of them works and one gives an error, but there are a range of options. Many simple scripts will have the same behaviour on common shells, but more complex scripts are likely to hit one of the many differences between the languages provided by different shells.
Will a script behave differently depending on your value of
SHELL? Only if the script either invokes
$SHELL itself, or tests or otherwise uses its value, directly or indirectly. Ordinary shell scripts generally will not, but they can.
Will a script behave differently depending on the parent shell from which it was invoked? Extremely rarely - the script would have to do a fair bit of work to detect that, to the extent that it would almost have to be on purpose.
I think your use case is running
./script.sh, which is a
sh script, from your interactive shell, which is
ksh. If that's right, we're in the last case above, and the script will almost certainly behave in the same way as if you were using any other shell yourself. The system will always start up a new
/bin/sh process and tell it to execute the script.
No, it doesn't make a difference.
#!/usr/bin/sh means "use
/usr/bin/sh to interpret this script so the value of your
$SHELL makes no difference.