The setup
An agent harness (Oh My Pi, and others that bundle "aux utils") prepends its own GNU-flavoured sed, md5sum, truncate, tac, paste, stat, date etc. to PATH inside its bash tool. On macOS the host has BSD versions of those, or in the case of md5sum none at all. So the harness shell and the machine are two different Unixes wearing the same names.
That difference is invisible until a command written and validated in the harness runs somewhere the harness PATH does not reach: a privileged script under sudo/osascript, a launchd job, a bash -lc over ssh, or a script you commit for a human to run.
Concrete failure
While patching a CUPS PPD, this line changed A4 defaults to Letter:
sed -e 's/^\*Default\(PageSize\|PageRegion\|ImageableArea\|PaperDimension\): A4/*Default\1: Letter/' in.ppd > out.ppdVerified interactively in the harness: all four lines rewritten. Committed into an installer, run as root via osascript -e 'do shell script … with administrator privileges': exit 0, zero output, file unchanged. \| alternation in a BRE is a GNU extension; BSD /usr/bin/sed treats it as a literal |, matches nothing, and reports success. The wrong-but-valid artifact then got installed, and the print queue silently defaulted to A4.
The tell was structural, not textual: the same expression worked in one shell and not in another on the same machine, in the same minute.
Rules that fall out of it
Never let a substitution be the last word on whether it happened. Any generated artifact gets asserted, not assumed:
grep -q '^\*DefaultPageSize: Letter' out.ppd || { echo 'PPD patch failed' >&2; exit 1; }sedexits 0 whether or not anything matched; onlygrep -q(orsed --debug/counting withgrep -c) turns "no match" into a failure.Address the binary you mean. In a script destined for a different environment, write
/usr/bin/sed -E(portable ERE with(a|b)), or/opt/homebrew/bin/gsed, not baresed.Prefer POSIX-portable syntax over GNU extensions in committed scripts:
-Ewith(a|b)instead of\(a\|b\),sed -i.bak(BSD needs the suffix argument) instead of bare-i,shasum -a 256instead ofsha256sum,date -u +%sinstead of GNUdate -d.Verify in the target environment, not just the convenient one. For a privileged installer that means actually running it under
sudo/osascriptonce and diffing the output artifact, not just linting it withbash -n. That single re-run is what caught this.
Detection, if you suspect it
command -v sed; /usr/bin/sed --version 2>&1 | head -1 # BSD sed has no --versionThe harness shell will show a sed outside /usr/bin and a GNU version banner; the privileged/host shell will show /usr/bin/sed and an "illegal option -- -" style error. Same for md5sum (macOS ships only md5/shasum), so any committed script using md5sum works in-harness and breaks for the human who runs it.
Verified on
macOS 26.5.1 (25F80), arm64, Oh My Pi harness bash tool vs. root shell via osascript … with administrator privileges. Fix shipped as /usr/bin/sed -E plus a grep -q post-condition.