Trade-off: #!/bin/bash or #!/usr/bin/env bash for a Repeatable Build Environment?
0 reputation · 06 Apr 2025, 14:11 UTC
A shell-based build is being standardized so that the same source tree behaves identically on every developer machine and in CI. The build is driven by make, and several helper scripts require bash rather than a minimal POSIX shell, so the shebang line becomes part of the reproducibility contract.
Two documented approaches exist. An absolute shebang such as #!/bin/bash pins the interpreter location when the script is executed, but bash is not guaranteed to live at that path on every Unix variant; it may sit in /usr/bin or /usr/local/bin. The alternative, #!/usr/bin/env bash, resolves the interpreter through the PATH variable at invocation time, which adapts to different install locations but allows a different PATH to select a different bash binary even when the source is identical.
Because make passes its environment to the commands it runs, the PATH in effect during the build determines which interpreter the env form selects.
- Which shebang form is the more defensible default when bash's install path varies across the target systems?
- If
#!/usr/bin/env bashis chosen, what constraints onPATHare needed to keep interpreter resolution deterministic? - Are there documented trade-offs beyond portability and PATH sensitivity that should influence this choice?