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`.
BeginnerTroubleshootingTroubleshooting: tools, portability, permissions and environment
Answer
Likely causes → BSD sed (macOS) requires a backup-suffix argument after -i. It takes your expression as the suffix and the filename as the script, so deploy.yaml is parsed as the d command followed by junk. GNU sed treats the suffix as optional and attached (-i.bak).
Diagnose → sed --version fails on macOS (BSD sed has no --version); command -v gsed shows whether GNU sed is installed.
Fix → Use a form both accept, or avoid in-place editing:
sed -i.bak 's/replicas: 2/replicas: 3/' deploy.yaml && rm -f deploy.yaml.bak # works on GNU and BSD
sed 's/replicas: 2/replicas: 3/' deploy.yaml > deploy.yaml.tmp && mv deploy.yaml.tmp deploy.yaml
For YAML specifically, use yq -i '.spec.replicas = 3' deploy.yaml.
Prevent → Run scripts in CI on Linux and macOS if both are supported, or require GNU tools on macOS (brew install gnu-sed coreutils) and detect them at start-up.
More on Troubleshooting: tools, portability, permissions and environment
A cleanup script fails on a developer's Mac with `date: illegal option -- d`.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