A script that works on Ubuntu fails in an Alpine-based CI image with `grep: unrecognized option: P`.
IntermediateTroubleshootingTroubleshooting: tools, portability, permissions and environment
Answer
Likely causes → Alpine uses BusyBox grep, which has no PCRE (-P) support. The script relies on Perl-style syntax such as \d, lookarounds or \K. macOS grep also lacks -P.
Diagnose →
readlink -f "$(command -v grep)" # /bin/busybox
grep --help 2>&1 | head -2
Fix → Rewrite with POSIX ERE, which every grep supports, or install GNU grep in the image:
grep -oE 'version=[0-9]+\.[0-9]+\.[0-9]+' file | cut -d= -f2 # instead of grep -oP 'version=\K[\d.]+'
apk add --no-cache grep bash coreutils # if GNU behaviour is required
Prevent → Prefer grep -E in scripts; reach for -P only in interactive use. Pin the CI image and run the script's tests inside it.
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 cleanup script fails on a developer's Mac with `date: illegal option -- d`.BeginnerAn `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