4 ms·
> I agree that the shebang should be #!/usr/bin/env bash though. That's not at all a given. This will use the first "bash" that it comes across, which has its
by Turing_Machine 3y ago
> I agree that the shebang should be #!/usr/bin/env bash though.
That's not at all a given.
This will use the first "bash" that it comes across, which has its good and bad points, while `#!/bin/bash` will use that specific one (if it exists). If J. Random User has been manipulated into installing a fake bash (or if the package installer or whatever has installed a fake bash) somewhere in his path, the env method can be very bad indeed. In general, that's going to be a far easier thing to do than installing a fake bash in /bin.
In general, /bin/bash is gonna work fine, either because that's where it actually is (the overwhelming majority of *nix systems in use today, including most or all Linuxes and macOS), or the system and/or system administrator has created a link from /bin/bash to where it's actually located.
It doesn't really gain you a whole lot anyway. If there's no guarantee that bash is located at /bin/bash, there's even less of a guarantee that env is located at /usr/bin/env.
- preseinger 3y ago/usr/bin/env is reliably present -- a system without this executable is basically non-functional, right? /bin/bash is not reliably present -- there is no guarantee that bash exists on a system at all, really!
- Turing_Machine 3y ago> /usr/bin/env is reliably present -- a system without this executable is basically non-functional, right? It doesn't have to be in /usr/bin.
- preseinger 3y agoi'm not aware of any modern system where this would be the case some ancient rhel systems put it in /bin/env, i believe, but in that case they usually symlink /usr/bin/env to it, or /usr/bin to /bin at least
- preseinger 3y ago> If there's no guarantee that bash is located at /bin/bash, there's even less of a guarantee that env is located at /usr/bin/env. i've seen way more systems that don't have a global /bin/bash than systems that don't have a /usr/bin/env as an example, /bin/bash on macos is forever stuck at version 3.2.something, if i run across a bash script that uses crazy features like associative arrays, i definitely want it to use the modern version of bash i've installed to my $HOME/bin/bash