Shell script written in a different shell than what my current shell Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Shell script written in a different shell than what my current shell without wasting too much if your time.

The question is published on by Tutorial Guruji team.

If the shell script is

#!/bin/sh

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.

Answer

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.

We are here to answer your question about Shell script written in a different shell than what my current shell - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji