ShellCheck – A shell script static analysis tool
The goals of ShellCheck are
- To point out and clarify typical beginner’s syntax issues that cause a shell to give cryptic error messages.
- To point out and clarify typical intermediate level semantic problems that cause a shell to behave strangely and counter-intuitively.
- To point out subtle caveats, corner cases, and pitfalls that may cause an advanced user’s otherwise working script to fail under future circumstances.
v0.6.0 – 2018-12-02
- Command line option –severity/-S for filtering by minimum severity
- Command line option –wiki-link-count/-W for showing wiki links
- SC2152/SC2151: Warn about bad
- SC2236/SC2237: Suggest -n/-z instead of ! -z/-n
- SC2238: Warn when redirecting to a known command name, e.g. ls > rm
- SC2239: Warn if the shebang is not an absolute path, e.g. #!bin/sh
- SC2240: Warn when passing additional arguments to dot (.) in sh/dash
- SC1133: Better diagnostics when starting a line with |/||/&&
- Most warnings now have useful end positions
- SC1117 about unknown double-quoted escape sequences has been retired
- SC2021 no longer triggers for equivalence classes like
- SC2221/SC2222 no longer mistriggers on fall-through case branches
- SC2081 about glob matches in
[ .. ]now also triggers for
- SC2086 no longer warns about spaces in
- SC2164 no longer suggests subshells for
cd ..; cmd; cd ..
read -ais now correctly considered an array assignment
- SC2039 no longer warns about LINENO now that it’s POSIX
On Debian based distros:
apt-get install shellcheck
On Arch Linux based distros:
pacman -S shellcheck
On the web
Paste a shell script on https://www.shellcheck.net for instant feedback.
From your terminal
Run shellcheck yourscript in your terminal for instant output, as seen above.
In your editor
You can see ShellCheck suggestions directly in a variety of editors.
- Emacs, through Flycheck:
- Sublime, through SublimeLinter.
- Atom, through Linter.
- VSCode, through vscode-shellcheck.
- Most other editors, through GCC error compatibility.
In your build or test suites
While ShellCheck is mostly intended for interactive use, it can easily be added to builds or test suites.
It makes canonical use of exit codes and can output simple JSON, CheckStyle compatible XML, GCC compatible warnings as well as human-readable text (with or without ANSI colors).
Copyright 2012-2018, Vidar ‘koala_man’ Holen and contributors.