SHELLCHECK(1) General Commands Manual SHELLCHECK(1) (NAME) shellcheck - (SYNOPSIS) shellcheck [OPTIONS...] FILES... (DESCRIPTION) ShellCheck (linting) sh/bash . (corner cases) . ShellCheck . : (( area = 3.14*r*r )) o #!/bin/sh ( -s sh) ShellCheck (( .. )) POSIX ( checkbashisms). o #!/bin/bash ( -s bash) ShellCheck . o #!/bin/ksh ( -s ksh) ShellCheck ksh . (OPTIONS) -a, --check-sourced (sourced) . shellcheck . (sourced) . -C[WHEN], --color[=WHEN] TTY : always () never () auto (). auto . --color --color=always . -i CODE1[,CODE2...], --include=CODE1[,CODE2...] . -i . (include) (exclude) . -e CODE1[,CODE2...], --exclude=CODE1[,CODE2...] . -e . --extended-analysis=true/false / (Dataflow Analysis) ( true). ShellCheck CPU/RAM (directive) . rc . -f FORMAT, --format=FORMAT shellcheck . -f FORMATS . --list-optional . -o enable . --norc .shellcheckrc . --rcfile RCFILE . -o NAME1[,NAME2...], --enable=NAME1[,NAME2...] . all . -o . enable . -P SOURCEPATH, --source-path=SOURCEPATH (sourced) : ; . search-path . -s shell, --shell=shell Bourne . sh bash dash ksh busybox. shell (shebang) .bash/.bats/.dash/.ksh ( ) . sh sh POSIX ( ) . -S SEVERITY, --severity=severity (severity) . error warning info style. style . -V, --version . -W NUM, --wiki-link-count=NUM TTY NUM . 0 . -x, --external-sources source . shellcheck ( /dev/null) . source . external-sources=true .shellcheckrc . . FILES... "-" ..SH " (FORMATS)" tty . . gcc GCC. . Vim :set makeprg=shellcheck\ -f\ gcc\ % :make :cnext . ::: : checkstyle XML Checkstyle. IDE . ... ... diff unified diff. git apply patch -p1 (pipe) . --- a/test.sh +++ b/test.sh @@ -2,6 +2,6 @@ ## Example of a broken script. for f in $(ls *.m3u) do - grep -qi hq.*mp3 $f \ + grep -qi hq.*mp3 "$f" \ && echo -e 'Playlist $f contains a HQ file in mp3 format' done json1 Json . json ShellCheck . (Tabs) . { comments: [ { "file": "filename", "line": lineNumber, "column": columnNumber, "level": "severitylevel", "code": errorCode, "message": "warning message" }, ... ] } json (legacy) json1 . (comments) (tab stop) . quiet . . ..SH " (DIRECTIVES)" ShellCheck . (file-wide) . : # shellcheck key=value key=value command-or-structure SC2035 ./*.jpg: # shellcheck disable=SC2035 echo "Files: " *.jpg ShellCheck: # shellcheck source=./lib.sh source "$(find_install_dir)/lib.sh" (brace group) : # shellcheck disable=SC2016 { echo 'Modifying $PATH' echo 'PATH=foo:$PATH' >> ~/.bashrc } : disable . echo foo subshell . disable=SC3000-SC4000 3xxx. disable=all . enable --list-optional . enable . extended-analysis true/false / (dataflow analysis). # shellcheck extended-analysis=false ( ) ShellCheck . . external-sources true .shellcheckrc ShellCheck 'source' ( ). ShellCheck false . . source source/. . /dev/null . source-path source/. ( ShellCheck ). . SCRIPTDIR source-path=SCRIPTDIR source-path=SCRIPTDIR/../libs. -P . shell shebang . ( shebang ) 'disable=SC2039' ..SH " (RC FILES)" --norc ShellCheck .shellcheckrc shellcheckrc . key=value . .shellcheckrc : # Look for 'source'd files relative to the checked script, # and also look for absolute paths in /mnt/chroot source-path=SCRIPTDIR source-path=/mnt/chroot # Since 0.9.0, values can be quoted with '' or "" to allow spaces source-path="My Documents/scripts" # Allow opening any 'source'd file, even if not specified as input external-sources=true # Turn on warnings for unquoted variables with safe values enable=quote-safe-variables # Turn on warnings for unassigned uppercase variables enable=check-unassigned-uppercase # Allow [ ! -z foo ] instead of suggesting -n disable=SC2236 .shellcheckrc ShellCheck ~/.shellcheckrc $XDG_CONFIG_HOME ( ~/.config/shellcheckrc) %APPDATA%/shellcheckrc . . Snap: (Sandbox) . shellcheckrc . Docker: ShellCheck (mount) ~/.shellcheckrc . (ENVIRONMENT VARIABLES) SHELLCHECK_OPTS : export SHELLCHECK_OPTS='--shell=bash --exclude=SC2016' . (RETURN VALUES) ShellCheck : o 0: . o 1: . o 2: ( ). o 3: ShellCheck ( ). o 4: ShellCheck ( ). (LOCALE) ShellCheck . UTF-8 ISO-8859-1 . LC_CTYPE ( C) UTF-8 . commitBuffer: invalid argument (invalid character) chcp 65001 UTF-8 . (KNOWN INCOMPATIBILITIES) ( ) ShellCheck { brace groups; } ( subshells ) []*=! function . Bash ShellCheck . [x!=y] () [[ $1 ]] function [x!=y] () { [[ $1 ]]; } function . {} . ShellCheck [x!=y] . '[x!=y]' (globbing) command [x!=y] . ShellCheck [ . [ $x= 1 ] POSIX ShellCheck [ "$x" = 1 ] . [ test \[ ..SH " (REPORTING BUGS)" GitHub : https://github.com/koalaman/shellcheck/issues (AUTHORS) ShellCheck Vidar Holen . (COPYRIGHT) 2012-2025 Vidar Holen . GNU General Public License 3 : https://gnu.org/licenses/gpl.html (SEE ALSO) sh(1), bash(1), dash(1), ksh(1) SHELLCHECK(1)