Shebang in Bash Scripts – Why Use /bin/sh Instead of /bin/bash?

bashhistoryshebangshell

In most shell scripts I've seen (besides ones I haven't written myself), I noticed that the shebang is set to #!/bin/sh. This doesn't really surprise me on older scripts, but it's there on fairly new scripts, too.

Is there any reason for preferring /bin/sh over /bin/bash, since bash is pretty much ubiquitous, and often default, on many Linux and BSD machines going back well over a decade?

Best Answer

  1. There are systems not shipping bash by default (e.g. FreeBSD).
  2. Even if bash is installed, it might not be located in /bin.
  3. Most simple scripts don't require bash.
  4. Using the POSIX shell is more portable and the scripts will run on a greater variety of systems.