3 ms·
Nice summary. Also pretty much a short list of reasons why I started to write even simple scripts in awk or python when they get too long. Another long topic is
by viraptor 15y ago
Nice summary. Also pretty much a short list of reasons why I started to write even simple scripts in awk or python when they get too long. Another long topic is quoting variables, $ inside strings and expansion before execution... Opinions may vary of course, but I've found it easier to just write this (or whatever you need) and deal with normal variables and normal lex-and-parse-before-expansion/execution language:
echo 'abcdefghijklm\nop
123456789' | awk '{print}'
- BrandonM 15y agoI 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).