I've been adding a shebang at the start of my scripts as a good practice, using `#!/bin/bash` in all my projects, including my linutils and a few other repositories that depend on bash. However, since I started using NixOS, I'm getting an error about a bad interpreter. I came across the alternative shebang `#!/usr/bin/env bash`. Should I be using this in all my repositories that are meant to run on Debian, Arch, or Fedora? Is it considered universally acceptable?
2 Answers
I actually disagree with relying on `#!/usr/bin/env bash`. The shebang should point to the specific interpreter version that's required for the script. Users might have different versions installed, and using `env` can lead to compatibility issues if one script needs a newer version than what's available. It's better for the script to specify the expected environment explicitly.
If one script needs a specific version of bash and another needs a different one, they both might use the same `env` shebang but fail on the user’s system if the required version isn’t available. It's more reliable to set up the right shebang for the expected version.
Yes, using `#!/usr/bin/env bash` is often seen as a safer practice. It allows the script to find bash regardless of where it's installed on the user's system.

What's the difference? Why does specifying the version matter?