4 ms·
`#!/usr/bin/env bash` is the most portable form for executing it from $PATH
by Crestwave 11mo ago
`#!/usr/bin/env bash` is the most portable form for executing it from $PATH
- hamandcheese 11mo agoIs this meaningfully more portable than #!bash though?
- tombert 11mo agoIn a sibling thread someone pointed out that #!bash doesn't actually work if you're calling it from bash, and appears to only work with zsh. I just tried it and they were absolutely right, so `#!/usr/bin/env bash` is definitely more portable in that it consistently works.
- saurik 11mo agoThis mechanism doesn't do a PATH lookup: #!bash would only work if bash was located in your current working directory.
- Ferret7446 11mo agoI raise you a https://www.felesatra.moe/blog/2021/07/03/portable-bash-shebang https://www.felesatra.moe/blog/2021/07/03/portable-bash-sheb... Pedantic, but "#!" and "portable" don't belong in the same sentence
- Crestwave 10mo agoThe script you posted is only portable in theory and not in practice. Executing it while using a non-POSIX shell like Elvish (even without having it as a default shell) makes it immediately fail. Meanwhile, `#!/usr/bin/env` is completely portable in the practical sense. Even systems with non-standard paths like NixOS, Termux and GoboLinux patch in support for it specifically.