Utility dialects and platform assumptions
Interpreter compatibility and utility compatibility are independent. Bash can run on Linux, macOS or WSL, but the external stat, sed, date, readlink and other tools can differ. GNU stat uses stat -c %s file for byte size; FreeBSD stat uses stat -f %z file (documented, not executed here). Some BusyBox builds implement GNU-like flags, but applets and options depend on configuration. For a byte count of ordinary readable content, wc -c < file avoids a dialect-specific stat option, although it reads data instead of querying metadata. Avoid assuming that sed -i has identical syntax: use a separate output file, verify it, and only then deliberately replace an owned target if needed. Avoid GNU-specific date parsing when portability matters; define an explicit date format and test on each target. uname -s identifies the kernel family, not the exact utility implementation. WSL may expose a Linux toolchain with Windows-mounted filesystem behavior; native Windows shells, WSL and macOS are separate test lanes. Use a known PATH, explicit dependency checks, and fixture-owned paths. Do not silently install missing tools or overwrite real files. Check fixture writes and the byte-count command before interpreting its result as an integer. The separate sed output example checks transformation success before displaying the files.
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.
Count bytes without stat flags
printf 'abc\n' > sample.txt || exit 1bytes=$(wc -c < sample.txt) || exit 1printf 'bytes=%s\n' "$((bytes))"Expected stdout:
bytes=4The newline is also a byte. This counts content rather than filesystem metadata.
Compare local stat implementations
printf 'abc\n' > sample.txt || exit 1printf 'GNU: 'stat -c %s sample.txt || exit 1printf 'BusyBox: 'busybox stat -c %s sample.txt || exit 1Expected stdout:
GNU: 4BusyBox: 4Both installed variants accept this option; it says nothing about BSD stat.
Write a separate transformed file
printf 'draft\n' > input.txt || exit 1sed 's/draft/final/' input.txt > output.txt || exit 1cat input.txt output.txtExpected stdout:
draftfinalThe original remains intact; no in-place sed dialect is needed.
Common mistakes
An OS name or a successful Bash test does not certify external flags. Do not parse ls output or assume every BusyBox applet is enabled.
Practice
Compare byte counts using wc and stat in a private directory. Record exact utility variants and mark BSD/macOS results unavailable unless actually tested.
Next: Locale, CRLF and filenames