Why is #!/usr/bin/env bash superior to #!/bin/bash?

#!/usr/bin/env searches PATH for bash, and bash is not always in /bin, particularly on non-Linux systems. For example, on my OpenBSD system, it’s in /usr/local/bin, since it was installed as an optional package.

If you are absolutely sure bash is in /bin and will always be, there’s no harm in putting it directly in your shebang—but I’d recommend against it because scripts and programs all have lives beyond what we initially believe they will have.

Leave a Comment