3 ms·
> then you have to add a shebang line directly to the script itself, which I always feel uncomfortable since it's hard-coded (what if in future I don't want to
by kibwen 2y ago
> then you have to add a shebang line directly to the script itself, which I always feel uncomfortable since it's hard-coded (what if in future I don't want to execute my .py script with `/usr/bin/python` but `/usr/bin/nohtyp`?)
> But I really, really just want to run `hello` to call a `hello.py` script that is in my $PATH.
On Linux I'd say the shebang is still the right tool for this. If you want a lightweight approach, just have a `my_python` symlink in your path, then your shebang can be `/usr/bin/env my_python` (or heck just `/foo/bar/baz/my_python`, /usr/bin/env is already an abstraction).
If you want a more principled approach, look at the `update-alternatives` tool, which provides this sort of abstraction in a more general way: https://linuxconfig.org/how-to-set-default-programs-using-update-alternatives-on-debian-based-distributions https://linuxconfig.org/how-to-set-default-programs-using-up...
- ffsm8 2y ago> /usr/bin/env is already an abstraction). Isn't that path and the behavior of the binary defined by POSIX though? I thought it's as stable as you can get. That's why it's usually recommended that you use /use/bin/env bash vs /bin/bash in the shebang, as the latter isn't defined by POSIX
- kibwen 2y agoYes, env is an abstraction for the sake of portability, but if you're setting up custom indirections then portability probably isn't much of a concern.
- rascul 2y ago> Isn't that path and the behavior of the binary defined by POSIX though? I thought it's as stable as you can get. I don't see anything about the path being defined. Certainly possible I missed it, though. I'm not able to check right now but I vaguely recall that I've used a system in the past with env in a location other than /usr/bin.