Hacker News new | ask | show | jobs
by chungy 1365 days ago
> Why not make all your shell scripts #!/bin/bash

Because it's not always installed there. See, for example, FreeBSD where bash typically lives in /usr/local/bin/bash. Or in the Linux world, Nix and Guix.

Use "#!/usr/bin/env bash" to account for all these possibilities.

2 comments

If we're going to be pedantic, env doesn't have to be installed at /usr/bin/env either. See https://www.felesatra.moe/blog/2021/07/03/portable-bash-sheb...
i cant remember where I saw it now, or what the main argument was, but I remember reading a rather authoritative article recommending against the env approach, and recommending people stick to #!/bin/bash regardless of the above, otherwise valid point.

Dunno if anyone here with a better memory remembers the article to link here ...