A cleanup script fails on a developer's Mac with `date: illegal option -- d`.
BeginnerTroubleshootingTroubleshooting: tools, portability, permissions and environment
Answer
Likely causes → date -d '7 days ago' is a GNU extension. BSD date uses -v-7d for relative dates and -j -f to parse. readlink -f, stat -c and sed -r have the same GNU-only problem.
Diagnose → date --version 2>/dev/null || echo "BSD date"; uname -s shows Darwin.
Fix → Branch once in a helper, or let find do the date math so no date arithmetic is needed:
days_ago() { # prints YYYY-MM-DD for N days ago on GNU or BSD date
if date --version >/dev/null 2>&1; then date -u -d "$1 days ago" +%F; else date -u -v-"$1"d +%F; fi
}
find /var/tmp/app -type f -mtime +7 -delete # portable, no date parsing at all
Prevent → Keep a small lib/compat.sh for platform differences, and test it on both platforms in CI.
More on Troubleshooting: tools, portability, permissions and environment
On a Mac, `sed -i 's/replicas: 2/replicas: 3/' deploy.yaml` fails with `sed: 1: "deploy.yaml": extra characters at the end of d command`.BeginnerA script that works on Ubuntu fails in an Alpine-based CI image with `grep: unrecognized option: P`.IntermediateAn `awk` one-liner works on your RHEL box but fails on Ubuntu with `awk: line 1: function gensub never defined`.Intermediate`comm -23 expected.txt installed.txt` prints `comm: file 1 is not in sorted order`, even though both files were produced with `sort`.Intermediate`grep ERROR /var/log/app/app.log` prints only `grep: /var/log/app/app.log: binary file matches`.BeginnerOn macOS, `tr '[:lower:]' '[:upper:]' < export.csv` fails with `tr: Illegal byte sequence`, and `sed` gives `sed: RE error: illegal byte sequence`.Intermediate