ShellCheck and shfmt
ShellCheck analyzes shell source for common mistakes, while shfmt normalizes formatting. Neither replaces running a test. For instance, an unquoted scalar can split into multiple arguments or expand filename patterns; syntax checking may accept it. Correct the quoting based on intended semantics rather than suppressing every warning. In an environment with these tools installed, inspect shellcheck --version and shfmt --version, then run shellcheck -s bash demo.sh and shfmt -d demo.sh against the synthetic file in example 1. The diff mode reports formatting differences without rewriting; shfmt -w rewrites, so review before using it. A targeted suppression is appropriate only with an explained reason. These tool commands are DOCUMENTED / NOT RUN here: neither tool is installed; no actual warning codes, version or formatting output is asserted. The three runnable examples below demonstrate the underlying behavior using Bash alone. The deliberately incorrect arithmetic implementation is a teaching demonstration: its final diagnostic succeeds. A real regression test should return nonzero when the result is wrong.
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.
A syntactically valid quoting bug
cat > demo.sh <<'END' || exit 1#!/usr/bin/env bashlabel='daily report'printf '[%s]\n' $labelENDbash -n demo.sh && bash demo.shExpected stdout:
[daily][report]The unquoted expansion changes the argument count. This is a runtime illustration, not a ShellCheck result.
Repair argument boundaries
Expected stdout:
[daily report]Quoting preserves one argument.
Formatting cannot repair logic
total() { printf '%s\n' "$(( $1 - $2 ))"}actual=$(total 5 3)if [[ $actual == 8 ]]; then printf 'pass\n'else printf 'wrong result: %s\n' "$actual"fiExpected stdout:
wrong result: 2The function is readable but subtracts instead of adding.
Common mistakes
Do not claim that a clean formatter result proves correctness. Do not turn off lint globally to hide a real defect. Check the interpreter and dialect before choosing lint and formatting settings.
Practice
Write a small Bash script that receives a filename containing spaces. Test its behavior, then if available run ShellCheck and shfmt in diff mode. Explain separately what each check establishes; record NOT RUN for unavailable tools.
Next: Bats and shell test design