← All posts

Testing

ShellCheck: Catch the Bugs Hiding in Your Shell Scripts

ShellCheck is a static analysis tool that finds bugs and pitfalls in your shell scripts before they bite you.

S Testing

Shell scripting is a minefield of quiet traps: an unquoted variable that breaks on a space, a comparison that always passes, a glob that expands when you didn't mean it to. These bugs don't announce themselves - they just do the wrong thing later. ShellCheck is the tool that finds them first. It statically analyzes your bash and sh scripts and flags the mistakes, explaining each one and usually suggesting the fix, so your scripts fail at review instead of at runtime.

The Warnings You Need to See

Point it at a script and it reports issues with codes you can look up and learn from:

# Check a script shellcheck deploy.sh # It flags things like: # unquoted $var that will break on spaces # [ $x = y ] that should be quoted # useless use of cat, and dozens more

It Teaches as It Checks

Each finding links to an explanation of why it's a problem and how to fix it, so over time ShellCheck doesn't just clean your scripts - it makes you a better shell programmer. It integrates into editors and CI, so the feedback shows up while you write rather than after you ship.

Rough Edges and Limitations

  • Static, not runtime. It catches structural mistakes, not logic errors in what your script is trying to do.
  • The occasional false positive. A few warnings need a deliberate inline suppression when you know better.
  • POSIX/bash focus. Very shell-specific or exotic constructs may get flagged conservatively.

If you write shell scripts of any consequence, ShellCheck is close to mandatory - it catches the class of bug that's hardest to spot by eye.

Internal link suggestion: link "integrates into ... CI" to the pre-commit or lefthook post for running it automatically.