Change `#!/bin/bash` shebangs to `#!/usr/bin/env bash` for better compatibility
See original GitHub issueSome operating systems don’t have a Bash executable located at /bin/bash
(e.g. NixOS does this intentionally), so shell scripts using #!/bin/bash
as their shebang won’t function without modification.
I suggest replacing #!/bin/bash
with #!/usr/bin/env bash
to improve compatibility with systems that don’t have /bin/bash
.
I’m willing to implement this change — it’s a pretty simple change — but I’m presenting the idea first as an issue.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:5 (1 by maintainers)
Top Results From Across the Web
What is the preferred Bash shebang ("#!")?
You should use #!/usr/bin/env bash for portability: Different *nixes put bash in different places, and using /usr/bin/env is a workaround to ...
Read more >Is there any reason to have a shebang pointing at /bin/sh ...
This means that I always use #!/bin/bash in my shebang unless I have verified that I don't have bashims in my script. By...
Read more >What is the preferred Bash shebang ("#!")? : r/commandline
I am really confused between shebangs for Bash Script (.bash) and Shell Script (.sh). Is there any Bash shebang objectively better than the ......
Read more >The Difference Between #!/usr/bin/bash and #!/usr/bin/env ...
#!/usr/bin/bash is a shebang line used in script files to set bash, present in the '/bin' directory, as the default shell for executing...
Read more >Make Linux Script Portable With #!/usr/bin/env As a Shebang
Learn how to make Linux/Unix script portable with #!/usr/bin/env shebang to execute script using the interpreter such as bash, perl, python.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That might be the case if you have binaries in setuid scripts (very bad idea in the first place). But than you also need to do a lot of hardening in general i.e. use absolute PATHs everyhere or set your own PATH and sanitize other environment variables. I don’t think this applies here.
Nixpkgs/NixOS maintainer here. It is not just NixOS and Guix. FreeBSD has
bash
in/usr/local/bin
. MacOS bash at/bin/bash
is ancient and people might want to replace it with homebrew’s bash. Also see this discussion in systemd: https://github.com/systemd/systemd/pull/5816 TL;DR upstream should rely on the developers/user’s PATH for flexibility. Linux distribution have control over their binaries during packaging and have infrastructure replace/usr/bin/env
shebangs automatically with absolute paths to the right binaries.