shellcheck man page

shellcheck — Shell script analysis tool


shellcheck [Options...] FILES...


ShellCheck is a static analysis and linting tool for sh/bash scripts. It's mainly focused on handling typical beginner and intermediate level syntax errors and pitfalls where the shell just gives a cryptic error message or strange behavior, but it also reports on a few more advanced issues where corner cases can cause delayed failures.

ShellCheck gives shell specific advice. Consider this line:

(( area = 3.14*r*r ))


-C[WHEN], --color[=WHEN]

For TTY output, enable colors always, never or auto. The default is auto. --color without an argument is equivalent to --color=always.

-e CODE1[,CODE2...], --exclude=CODE1[,CODE2...]

Explicitly exclude the specified codes from the report. Subsequent -e options are cumulative, but all the codes can be specified at once, comma-separated as a single argument.

-f FORMAT, --format=FORMAT

Specify the output format of shellcheck, which prints its results in the standard output. Subsequent -f options are ignored, see Formats below for more information.

-s shell--shell=shell

Specify Bourne shell dialect. Valid values are sh, bash, dash and ksh. The default is to use the file's shebang, or bash if the target shell can't be determined.


Print version information and exit.


Follow 'source' statements even when the file is not specified as input. By default, shellcheck will only follow files specified on the command line (plus /dev/null). This option allows following any file the script may source.



Plain text, human readable output. This is the default.


GCC compatible output. Useful for editors that support compiling and showing syntax errors.

For example, in Vim, :set makeprg=shellcheck\ -f\ gcc\ % will allow using :make to check the script, and :cnext to jump to the next error.

<file>:<line>:<column>: <type>: <message>

Checkstyle compatible XML output. Supported directly or through plugins by many IDEs and build monitoring systems.

<?xml version='1.0' encoding='UTF-8'?>
<checkstyle version='4.3'>
  <file name='file'>
      source='ShellCheck.SC####' />

Json is a popular serialization format that is more suitable for web applications. ShellCheck's json is compact and contains only the bare minimum.

    "file": "filename",
    "line": lineNumber,
    "column": columnNumber,
    "level": "severitylevel",
    "code": errorCode,
    "message": "warning message"


ShellCheck directives can be specified as comments in the shell script before a command or block:

# shellcheck key=value key=value

For example, to suppress SC2035 about using ./*.jpg:

# shellcheck disable=SC2035
echo "Files: " *.jpg

To tell ShellCheck where to look for an otherwise dynamically determined file:

# shellcheck source=./
source "$(find_install_dir)/"

Here a shell brace group is used to suppress a warning on multiple lines:

# shellcheck disable=SC2016
  echo 'Modifying $PATH'
  echo 'PATH=foo:$PATH' >> ~/.bashrc

Valid keys are:


Disables a comma separated list of error codes for the following command. The command can be a simple command like echo foo, or a compound command like a function definition, subshell block or loop.


Overrides the filename included by a source/. statement. This can be used to tell shellcheck where to look for a file whose name is determined at runtime, or to skip a source by telling it to use /dev/null.

Environment Variables

The environment variable SHELLCHECK_OPTS can be set with default flags:

export SHELLCHECK_OPTS='--shell=bash --exclude=SC2016'

Its value will be split on spaces and prepended to the command line on each invocation.

Return Values

ShellCheck uses the follow exit codes:


This version of ShellCheck is only available in English. All files are leniently decoded as UTF-8, with a fallback of ISO-8859-1 for invalid sequences. LC_CTYPE is respected for output, and defaults to UTF-8 for locales where encoding is unspecified (such as the C locale).

Windows users seeing commitBuffer: invalid argument (invalid character) should set their terminal to use UTF-8 with chcp 65001.


ShellCheck is written and maintained by Vidar Holen.

Reporting Bugs

Bugs and issues can be reported on GitHub:

See Also

sh(1) bash(1)


Shell script analysis tool