$linuxjunkies
>

shellcheck(1)

ShellCheck is a static analysis tool that finds bugs and potential issues in shell scripts.

UbuntuDebianFedoraArch

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

FlagWhat it does
-f FORMAToutput format: gcc, json, json1, csv, sarif, or tty (default: tty)
-xfollow source files in shell scripts (. and source)
-S SEVERITYonly show issues of given severity: error, warning, info, style
--exclude=CODEexclude specific diagnostic codes (e.g., SC2086,SC2181)
-d DISABLEDdisable specific optional checks
--shell=SHELLassume script is in given shell: bash, sh, ksh, zsh, dash
--external-sourcescheck external script dependencies
-C CHECKenable optional check categories
--versiondisplay ShellCheck version
--helpshow help message

Examples

check a single shell script and display issues in terminal format

shellcheck script.sh

check all shell scripts in current directory

shellcheck *.sh

output results in JSON format for programmatic processing

shellcheck -f json script.sh | jq

check script but ignore unquoted variable expansion warnings

shellcheck --exclude=SC2086 script.sh

check script assuming bash dialect explicitly

shellcheck --shell=bash script.sh

check main.sh and follow all sourced files recursively

shellcheck -x main.sh

show only errors, suppress warnings and style suggestions

shellcheck -S error script.sh

output in GCC format for IDE integration and filter by type

shellcheck -f gcc script.sh | grep warning

Related commands