6 ms·
What's wrong with `#!/usr/bin/env sh`?
by Twisol 8y ago
What's wrong with `#!/usr/bin/env sh`?
- dwheeler 8y agoPOSIX doesn't include shebang (#!) at all. It should, but it currently doesn't.
- oblio 8y ago> currently doesn’t Yeah, we should be gentle with POSIX, it’s only 30 years young :)
- xyzzyz 8y agoNewest revision is from 2017, so they certainly had time to fix that, if they consider it a problem.
- jwilk 8y agoIt doesn't include /usr/bin/ either. The "env" utility could be somewhere else.
- _kst_ 8y agoI've worked on systems where env was installed as /bin/env and not as /usr/bin/env . (I think it was SunOS 4.) For that matter, under Termux on Android it's /data/data/com.termux/files/usr/bin/env (but termux has a hack to make normal shebangs work).
- jwilk 8y agohttps://www.in-ulm.de/~mascheck/various/shebang/#env https://www.in-ulm.de/~mascheck/various/shebang/#env mentions other OSes that have only /bin/env, although admittedly they are all quite old.
- dredmorbius 8y agoTermux rewrites scripts via termux-fix-shebang.
- rkeene2 8y agoIt now also does rewriting on the fly for certain shebang lines, as part of its C library, so unmodified scripts can run.
- dredmorbius 8y agoI didn't know that, thanks.
- rkeene2 8y agoNo problem. I wrote it because I version control my scripts and didn't want to fork them for running them on my laptop (Chromebook with Termux).
- dredmorbius 8y agoTry that where env ain't there. Android, motherfuckers.
- xyproto 8y ago"/usr/bin/env" is relying on a binary being present in a specific location just as much as relying on a binary being present in "/bin/bash". For most distros and BSDs, "/usr/bin/env" is more likely to be present, but it's not guaranteed for neither "/bin/bash" nor "/usr/bin/env".