shellcheck(1)
ShellCheck is a static analysis tool that finds bugs and potential issues in shell scripts.
Synopsis
shellcheck [OPTIONS] FILE...Description
ShellCheck scans shell scripts for common mistakes, syntax errors, and non-portable constructs. It provides warnings and suggestions to improve script quality and compatibility across different shell interpreters (bash, sh, ksh, zsh).
ShellCheck outputs diagnostic codes (SC####) for each issue, making it easy to suppress false positives or understand categories of problems. It works with bash, sh, dash, ksh, and zsh scripts.
Common options
| Flag | What it does |
|---|---|
-f FORMAT | output format: gcc, json, json1, csv, sarif, or tty (default: tty) |
-x | follow source files in shell scripts (. and source) |
-S SEVERITY | only show issues of given severity: error, warning, info, style |
--exclude=CODE | exclude specific diagnostic codes (e.g., SC2086,SC2181) |
-d DISABLED | disable specific optional checks |
--shell=SHELL | assume script is in given shell: bash, sh, ksh, zsh, dash |
--external-sources | check external script dependencies |
-C CHECK | enable optional check categories |
--version | display ShellCheck version |
--help | show help message |
Examples
check a single shell script and display issues in terminal format
shellcheck script.shcheck all shell scripts in current directory
shellcheck *.shoutput results in JSON format for programmatic processing
shellcheck -f json script.sh | jqcheck script but ignore unquoted variable expansion warnings
shellcheck --exclude=SC2086 script.shcheck script assuming bash dialect explicitly
shellcheck --shell=bash script.shcheck main.sh and follow all sourced files recursively
shellcheck -x main.shshow only errors, suppress warnings and style suggestions
shellcheck -S error script.shoutput in GCC format for IDE integration and filter by type
shellcheck -f gcc script.sh | grep warning