The way to write a command so every target runs it: bash 3.2 on macOS, GNU and BSD userlands, busybox, dash as /bin/sh, Git Bash on Windows, and fish and zsh where a file is shared with them. Each row is a spelling that has been gotten wrong here at least once. Write is what to use, Not what it replaces, Breaks on the target that fails and how, and Caught by what stops it coming back: a lint row (drift’s tables, dialects, shellcheck, shfmt), a suite, or - where no pattern can tell the right use from the wrong one - review, with the failure it was learned from.
Why a construct looks the way it does is GLOSSARY.md’s job; a row here links the entry rather than restating it. A new row belongs here the first time a spelling costs a CI round trip.
sed -r, or a backslash-bar alternation in a basic sed
BSD sed (macOS, FreeBSD, OpenBSD): -r is unknown and backslash-bar is a literal bar, so the match silently fails
drift
sed … >"$tmp" then _hi_write_back
sed -i
BSD takes an argument after -i, GNU does not (HI.08, HI.09)
drift
grep -E 'a\|b', or -e a -e b
a backslash-bar alternation in a basic grep
BSD grep (OpenBSD): backslash-bar is a literal bar, so nothing matches
drift
grep -E
grep -P
BSD and busybox grep have no PCRE
drift
sed '$d' to drop the last line
head -n -1
BSD and busybox head take no negative count
drift
awk as POSIX writes it
gawk’s gensub, strftime, \y, arrays of arrays
mawk, busybox awk, and onetrue (BSD) awk; the include scan is checked against all four
drift (the gawk-only functions); the include scan is run under all four in review
Pipes under strict mode
Write
Not
Breaks on
Caught by
printf '%s\n' "$x" \| grep -E pat >/dev/null
printf '%s\n' "$x" \| grep -q pat under pipefail
OpenBSD, intermittently: grep -q leaves at its first match, the writer gets SIGPIPE (141), and pipefail fails the pipeline - OpenBSD’s 1 KB stdio buffer turns a 1.4 KB input into two writes
drift, outside tests/; learned from the OpenBSD job’s release_notes.sh --check case, then configure.sh’s adopt scan
an awk that sets a flag and reads to the end
an awk that exits part-way through a piped input
the same SIGPIPE, and set -e then ends the script
review; the same failure
grep -q pat "$file"
—
nothing: a file argument has no writer to kill
—
( exec <&4 2>/dev/null; … ) & for a background job’s fds
{ … } <&4 2>/dev/null &
mksh and the pdksh-derived shs (OpenBSD’s): the group’s redirection leaves the shell’s saved copies of the original fds open in the job, so whatever reads the script’s output (an ssh channel, a $( )) waits for the job to end
review; learned from the overlapped connect’s piped stub
strict mode on at the top of a sourced file, off at its end
leaving set -euo pipefail on in a file an interactive shell sources
the user’s shell dies on the next non-zero status (HI.15)
drift
Output
Write
Not
Breaks on
Caught by
printf '%s\n' "$x"
echo -e, or echo of a backslash
dash and macOS’s POSIX-mode sh expand escapes that bash-as-sh prints as text
OpenBSD’s tar: -O writes an old-style archive, so the extract prints nothing
a suite
ps -A -o pid= -o ppid=
ps -eo pid=,ppid=
BSD ps: -e adds the environment, and the text after a = is the rest of the argument, so one column
test_lib_par, test_runner
ps -A -o … \|\| ps, and a process matched by its name alone
ps -o alone, or a match on its arguments
Git Bash: MSYS ps takes no -o, and its plain listing prints a command’s path without its arguments
test_runner
bash 3.2
macOS’s /bin/bash, and the floor: drift’s bash-4 table fails the build on each row caught by drift.
| Write | Not | Breaks on | Caught by | | ———————————————————– | —————————————————– | ———————————————————————————————- | ———————————————————– | | _hi_read_lines arr < <(cmd) | mapfile / readarray | bash 4 (HI.02) | drift | | parallel arrays | declare -A | bash 4 (HI.03) | drift | | printf -v "$1", or eval | local -n | bash 4.3 (HI.04) | drift | | printf -v into a plain variable, then a[i]="$v" | printf -v "a[i]", or printf -v "$1" handed a[i] | bash 3.2: “a[i]: not a valid identifier”, and the element keeps its old value | doctor_test, on the macOS job’s bash 3.2 | | tr '[:upper:]' '[:lower:]' | ${x,,} | bash 4 | drift | | ${a[@]+"${a[@]}"}, and a plain "${!a[@]}" | "${a[@]}" of a maybe-empty array, or ${!a[@]+…} | “unbound variable” under set -u (HI.01) | drift (the index form) | | comments above a $( … ), apostrophe-free inside one | a ' in a comment inside $( … ) | the whole file fails to parse (HI.29) | bash -n under the bash:3.2 image | | a case in a function the $( … ) or <( … ) calls | a case inside the $( … ) or <( … ) | the whole file fails to parse: “syntax error near unexpected token ;;'" | bash -n under the bash:3.2 image | | _hi_shquote | ${2//'/…} | 3.2 keeps the replacement's quoting ([HI.40](/say-hi/docs/GLOSSARY.html#hi40-hand-rolled-sh-quoting)) | hi_helpers and hi_dispatch, on the macOS job's bash 3.2 | | d=”${m%%/}”, then ${x//$d/…} | ${x//${m%%/}/…} | bash 3.2 ends the pattern at the / inside the nested expansion: "bad substitution" | drift | | if ((BASH_VERSINFO[0] > 4 || …)) around a newer builtin | printf ‘%(…)T’ unguarded | bash before 4.2 has no %(…)T` | the header suite on macOS |
Files shared with other shells
File
Dialect
Caught by
common/aliases.sh
what bash, zsh, and fish all parse: alias, export, && chains, backticks; no if or $( )
bash, zsh, and dash hand back the alias’s text, so the “binary” is alias ls='ls --color=auto' (HI.13)
alias_fallthrough; learned from the first ls of a session on Ubuntu
command sudo, command bash in an alias body
sudo as its own alias’s first word
fish’s alias function calls itself forever
aliases
$(command -v x >/dev/null 2>&1 && command x --flag … && echo …)
$(command x --flag 2>/dev/null && echo …) where x may be missing
fish: a command not found inside a $( ) drops the whole alias statement with “Unknown command”, and no redirect silences it; bash, zsh, and dash expand an empty string
review; learned from a user aliases.sh sourced by fish on a target without fd
Git Bash
Write
Not
Breaks on
Caught by
printf '… "%s" …\n' "$long"
a heredoc splicing a many-line value into the middle of a line
Git Bash never returns - no output, no error, only a timeout
one suite per file, sections split by an env var when a suite grows slow
one serial suite past a few minutes on Git Bash
the Windows shard it lands on becomes the run’s tail
test_runner’s shard checks
bash -i … >"$file" 2>&1, then read the file, or 2>/dev/null
out="$(bash -i … 2>&1)", or any pipe on an interactive shell’s stderr
FreeBSD and OpenBSD: their pipe ioctl answers TIOCGPGRP, so tcgetpgrp on a pipe returns 0 instead of failing, and bash takes the pipe for a terminal another group owns and stops itself with SIGTTIN before its first line - no output, state T, no terminal; Linux and macOS fail the call and carry on
the load suite’s process table on a failure; learned from the hooks-once case on both BSD jobs
got="$(cmd)" on its own line, then [ "$got" = … ] \|\| _hi_because "…$got"
[ "$(cmd)" = … ] inside a test’s assertion
every runner: drift’s case-reasons scan finds a compared substitution the failure cannot show, and the lint gate fails
drift, in the lint job and under coverage
a=(x y z) on one line in a script coverage measures
an array assignment spread over several lines
bashcov: xtrace prints the assignment once, on its last line, so every line above it reads as never run