3 ms·
I like that approach, and I usually find myself doing the same thing. Just be sure when writing a Python "executable" that the first line is: #!/usr/bin/env
by BrandonM 15y ago
I like that approach, and I usually find myself doing the same thing. Just be sure when writing a Python "executable" that the first line is:
#!/usr/bin/env python
Since python is not a POSIX-specified utility, it might be anywhere on the user's PATH. Using the env trampoline (it is guaranteed to be available at /usr/bin/env) will allow your script to work on any POSIX system that has Python installed and on the PATH.
In a brief search, I wasn't able to find a canonical location of awk defined in POSIX, so it might be necessary to use env for that, too.
- RegEx 15y ago#!/usr/bin/env python also ensures your scripts look for the virtualenv python when virtualenv is activated, but the system python when virtualenv is deactivated.
- dfox 15y agoPOSIX does not define canonical locations of any binaries, not even sh (Ahell & Utilities, sh, Application Usage). Only things that are specified in POSIX by exact path (Base Definitions, 10.1) are /dev/null, /dev/tty, /dev/console and /tmp. Using /usr/bin/env is common practice, but not standardized in any way. Also, POSIX does not specify the '#!' syntax, and only documents the original mechanism of running shell scripts (execl/vp() passes anything that is not understood by kernel to sh).