3 ms·
Use #!/usr/bin/env bash instead of #!/bin/bash. The former searches the user's PATH to find the bash binary. The latter assumes it is always instal
by usrbinbash 5y ago
Use #!/usr/bin/env bash instead of #!/bin/bash.
The former searches the user's PATH to find the bash binary.
The latter assumes it is always installed to /bin/ which can cause issues.
And the former assumes that `env` is installed in `/usr/bin`, so I am trading one assumption for another.
- fuzzybear3965 5y agoMaybe I shouldn't pick a battle with someone that has that handle . But, in all seriousness, you're right - you're making a trade. The question is which side of the trade is more portable. I use NixOS which doesn't have bash in /bin. So, I've had to ask people on my team to replace the hashbang. The /usr/bin/env hashbang has yet to fail on any machine so, anecdotally, it seems more portable.
- usrbinbash 5y agoIf something is portable to every *nix system which uses the Filesystem Hierarchie Standard (FHS), it's portable enough for every system I ever encountered or worked with. This isn't me ranting against systems with new ideas about file system layout, this is just me being pragmatic: When it works on all my work-, private- and production-machines, I see no reason to run an extra binary in front of all my shellscripts.
- fuzzybear3965 5y agoIf it doesn't support any of your users/co-workers then there's no need. But, there's nothing requiring the enforcement of the FHS in the linux kernel, so, generally, you can't take it's conformance for granted. If something works for X% of people and a trivial change makes it work for Y% of people (Y > X) then I advocate for making that trivial change.