Specify shell script interpreter

In general it is not appropriate to assume the default shell is Bash. Using a generic script shebang:

#!/bin/sh

will either:

  • use the default shell (which could be one of many shells)
  • invoke legacy Bourne Shell 1980s compatibility mode of your shell

Either way, a shell script using the general #!/bin/sh may fail on other computers. To improve shell script robustness, specify a particular shell with the shebang. Many Linux distros default to shells like:

To have even better cross-platform robustness, consider using Python instead of shell scripts.

Specify shell to run script

The default Linux shell is selectable in the shebang in the first line of the “my_script.sh” shell script. For example, to specify Bash shell, put as the first line:

#!/bin/bash

What is current shell

echo $SHELL

this $SHELL variable may not strictly be the “default” shell if you have scripts changing the shell on interactive login. Other users may choose a different default shell.

run script in specific shell

To run a script in a specific shell, do like:

bash my_script.sh

change default shell

To permanently change a user default shell on Linux, MacOS or Windows Subsystem for Linux, use chsh.