Cross-shell compatibility testing
Build a compatibility matrix with rows for features or test cases and columns for real interpreter versions, utility implementations, locales and target OS. Define expected stdout, stderr, status and filesystem effects before running a case. Use clean HOME, PATH and locale, a fresh fixture directory per execution, a timeout and trusted code only. A syntax check (shell -n file) catches parse failures, not runtime failures or incorrect results; execute separately. For a common POSIX subset, test Bash, Bash POSIX mode, dash and BusyBox ash independently. For a Bash-only script, assert its documented Bash result and record non-Bash observations as diagnostics rather than claiming unsupported shells are defective. A construct can parse but behave differently: an older shell may treat dollar-single quoting literally, and local may work even though the chosen POSIX edition does not require it. POSIX.1-2024 support is feature-specific, not established by a version label or passing a few tests. Mark missing Bash versions, BSD/macOS, WSL and alternative filesystems NOT RUN. The accompanying matrix records exact observations, not a standards certification. An unavailable interpreter is NOT RUN, not evidence that a feature is unsupported. Check its availability before probing an option. A successful syntax check can still be followed by a nonzero runtime status.
Practical examples
Run each example as a separate script in a fresh noninteractive Bash 5.2 process and empty practice directory. Tests use C locale; do not enter expected output as code.
Run a portable fixture in three shells
cat > common.sh <<'END' || exit 1set -- 'a b' ''printf '[%s]\n' "$@"ENDfor shell in bash dash; do "$shell" -n common.sh && "$shell" common.sh || exit 1donebusybox ash -n common.sh && busybox ash common.shExpected stdout:
[a b][][a b][][a b][]All three local interpreters preserve both arguments.
A syntax check is not execution
printf '%s\n' 'exit 7' > fail.sh || exit 1dash -n fail.sh || exit 1printf 'syntax=0\n'dash fail.shprintf 'runtime=%s\n' "$?"Expected stdout:
syntax=0runtime=7A valid script can deliberately return a failure status.
Probe pipefail without terminating the parent
command -v dash >/dev/null || exit 1command -v busybox >/dev/null || exit 1busybox ash -c : || exit 1if dash -c 'set -o pipefail' >/dev/null 2>&1; then printf 'dash: supported\n'else printf 'dash: unavailable\n'fiif busybox ash -c 'set -o pipefail' >/dev/null 2>&1; then printf 'ash: supported\n'else printf 'ash: unavailable\n'fiExpected stdout:
dash: supportedash: supportedThese results are for dash 0.5.12 and the installed BusyBox ash only. The child isolates an invalid option error.
Common mistakes
Never infer standards conformance from one successful shell, or equate syntax success with correct output. Keep unsupported, failed and unavailable lanes distinct.
Practice
Add a portable test for empty and spaced arguments and a Bash-only array probe. Record syntax, stdout, stderr and status in every available lane; do not claim untested versions.
Next: Advanced language semantics and internals