top | item 45989093

(no title)

nflekkhnnn | 3 months ago

Anything other than ”#!/usr/bin/env bash” is doomed to fail at some time.

discuss

order

hulitu|3 months ago

> Anything other than ”#!/usr/bin/env bash” is doomed to fail at some time.

if you have /usr/bin/env

kreetx|3 months ago

/usr/bin/env (and /bin/sh) are part of POSIX, that is why the above shebang is the recommended way to start a shell.

saghm|3 months ago

I don't know if this is still a thing, but I distinctly remember when playing around with NixOS years ago that `env` was the only thing in /usr/bin, which I assumed was pretty much exactly for this reason.

sgarland|3 months ago

If that fails, I assume the user knows enough about their environment to fix it.

normie3000|3 months ago

And is this shebang guaranteed to work always? Why isn't it more common?

jolmg|3 months ago

Because /bin is the standard location for bash. The only one that breaks that expectation is NixOS (and maybe GuixSD?), apparently. I'm surprised they didn't symlink /bin or put a stub. Last time I tried NixOS was like 10 years ago. I thought there was a /bin/bash, but maybe it was just a /bin/sh?

Other interpreters like python, ruby, etc. have more likelyhood of being used with "virtual environments", so it's more common to use /usr/bin/env with them.

int_19h|3 months ago

It's guaranteed to work provided that Bash is in the path.

It's very common for Python. Less so for Bash for two reasons: because the person who writes the script references /bin/sh instead (which is required to be there) even when they are writing bash-isms, or because the person who writes the script assumes that Bash is universally available as /bin/bash.

eyelidlessness|3 months ago

It’s quite common, although I probably see it used more frequently to invoke other (non-shell) scripting languages.