Specify shell script interpreter

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


will either use the default shell or invoke legacy Bourne Shell 1980s compatibility mode. 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. Popular shells besides Bash include Dash and Zsh, which is the MacOS default. To have even better cross-platform robustness, consider using Python instead of shell scripts.

The default 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:


The currently used shell is revealed by:

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.

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

bash my_script.sh

To permanently change user default shell use chsh.