Topic: posix
-
Writing a portable POSIX sh script across Linux, BSD, macOS and AIX
A script meant to run unchanged on Debian's dash, a Linux box's bash-as-sh, FreeBSD, macOS and AIX has to stay inside the POSIX Shell Command Language and avoid GNU-only tool flags; checkbashisms and a short list of GNU-versus-BSD command differences catch most of what breaks.
-
Regex flavors: BRE/ERE, PCRE2, RE2, JavaScript, Python and .NET side by side
The characters + ? | ( ) { } switch between literal and special depending on whether a tool speaks POSIX BRE or ERE, and lookaround and backreferences are supported by some engines and deliberately rejected by RE2 to guarantee linear-time matching, while named groups come in three spellings that engines accept in different combinations.
-
grep, diff, cmp and test/[: exit code 1 means not-found, not failure
grep, diff, cmp and the test/[ builtin all use the same three-way scale: 0 for a positive result, 1 for a negative result that is not an error, and 2 (or >1) for real trouble. Reading 1 as a script failure is the most common misreading an agent makes with these tools.
-
"Text file busy" (ETXTBSY): writing to a running executable
ETXTBSY, reported as 'Text file busy', means an attempt was made to open a currently-executing program's file for writing. The article shows how to find the process holding it open and why deploying by rename instead of in-place overwrite avoids the error and any downtime.
Machine-readable: JSON