blob: 90553b16b1971c70c3474c2987e627718d8ebf69 [file] [log] [blame]
.\" Automatically generated by Pandoc 2.2.1
.\"
.TH "SHELLCHECK" "1" "" "Shell script analysis tool" ""
.hy
.SH NAME
.PP
shellcheck \- Shell script analysis tool
.SH SYNOPSIS
.PP
\f[B]shellcheck\f[] [\f[I]OPTIONS\f[]...] \f[I]FILES\f[]...
.SH DESCRIPTION
.PP
ShellCheck is a static analysis and linting tool for sh/bash scripts.
It\[aq]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.
.PP
ShellCheck gives shell specific advice.
Consider this line:
.IP
.nf
\f[C]
((\ area\ =\ 3.14*r*r\ ))
\f[]
.fi
.IP \[bu] 2
For scripts starting with \f[C]#!/bin/sh\f[] (or when using
\f[C]\-s\ sh\f[]), ShellCheck will warn that \f[C]((\ ..\ ))\f[] is not
POSIX compliant (similar to checkbashisms).
.IP \[bu] 2
For scripts starting with \f[C]#!/bin/bash\f[] (or using
\f[C]\-s\ bash\f[]), ShellCheck will warn that decimals are not
supported.
.IP \[bu] 2
For scripts starting with \f[C]#!/bin/ksh\f[] (or using
\f[C]\-s\ ksh\f[]), ShellCheck will not warn at all, as \f[C]ksh\f[]
supports decimals in arithmetic contexts.
.SH OPTIONS
.TP
.B \f[B]\-a\f[],\ \f[B]\-\-check\-sourced\f[]
Emit warnings in sourced files.
Normally, \f[C]shellcheck\f[] will only warn about issues in the
specified files.
With this option, any issues in sourced files will also be reported.
.RS
.RE
.TP
.B \f[B]\-C\f[][\f[I]WHEN\f[]],\ \f[B]\-\-color\f[][=\f[I]WHEN\f[]]
For TTY output, enable colors \f[I]always\f[], \f[I]never\f[] or
\f[I]auto\f[].
The default is \f[I]auto\f[].
\f[B]\-\-color\f[] without an argument is equivalent to
\f[B]\-\-color=always\f[].
.RS
.RE
.TP
.B \f[B]\-i\f[]\ \f[I]CODE1\f[][,\f[I]CODE2\f[]...],\ \f[B]\-\-include=\f[]\f[I]CODE1\f[][,\f[I]CODE2\f[]...]
Explicitly include only the specified codes in the report.
Subsequent \f[B]\-i\f[] options are cumulative, but all the codes can be
specified at once, comma\-separated as a single argument.
Include options override any provided exclude options.
.RS
.RE
.TP
.B \f[B]\-e\f[]\ \f[I]CODE1\f[][,\f[I]CODE2\f[]...],\ \f[B]\-\-exclude=\f[]\f[I]CODE1\f[][,\f[I]CODE2\f[]...]
Explicitly exclude the specified codes from the report.
Subsequent \f[B]\-e\f[] options are cumulative, but all the codes can be
specified at once, comma\-separated as a single argument.
.RS
.RE
.TP
.B \f[B]\-f\f[] \f[I]FORMAT\f[], \f[B]\-\-format=\f[]\f[I]FORMAT\f[]
Specify the output format of shellcheck, which prints its results in the
standard output.
Subsequent \f[B]\-f\f[] options are ignored, see \f[B]FORMATS\f[] below
for more information.
.RS
.RE
.TP
.B \f[B]\-\-list\-optional\f[]
Output a list of known optional checks.
These can be enabled with \f[B]\-o\f[] flags or \f[B]enable\f[]
directives.
.RS
.RE
.TP
.B \f[B]\-\-norc\f[]
Don\[aq]t try to look for .shellcheckrc configuration files.
.RS
.RE
.TP
.B \f[B]\-o\f[]\ \f[I]NAME1\f[][,\f[I]NAME2\f[]...],\ \f[B]\-\-enable=\f[]\f[I]NAME1\f[][,\f[I]NAME2\f[]...]
Enable optional checks.
The special name \f[I]all\f[] enables all of them.
Subsequent \f[B]\-o\f[] options accumulate.
This is equivalent to specifying \f[B]enable\f[] directives.
.RS
.RE
.TP
.B \f[B]\-P\f[]\ \f[I]SOURCEPATH\f[],\ \f[B]\-\-source\-path=\f[]\f[I]SOURCEPATH\f[]
Specify paths to search for sourced files, separated by \f[C]:\f[] on
Unix and \f[C];\f[] on Windows.
This is equivalent to specifying \f[C]search\-path\f[] directives.
.RS
.RE
.TP
.B \f[B]\-s\f[]\ \f[I]shell\f[],\ \f[B]\-\-shell=\f[]\f[I]shell\f[]
Specify Bourne shell dialect.
Valid values are \f[I]sh\f[], \f[I]bash\f[], \f[I]dash\f[] and
\f[I]ksh\f[].
The default is to deduce the shell from the file\[aq]s \f[C]shell\f[]
directive, shebang, or \f[C]\&.bash/.bats/.dash/.ksh/.ebuild/.eclass\f[]
extension, in that order.
\f[I]sh\f[] refers to POSIX \f[C]sh\f[] (not the system\[aq]s), and will
warn of portability issues.
.RS
.RE
.TP
.B \f[B]\-S\f[]\ \f[I]SEVERITY\f[],\ \f[B]\-\-severity=\f[]\f[I]severity\f[]
Specify minimum severity of errors to consider.
Valid values in order of severity are \f[I]error\f[], \f[I]warning\f[],
\f[I]info\f[] and \f[I]style\f[].
The default is \f[I]style\f[].
.RS
.RE
.TP
.B \f[B]\-V\f[],\ \f[B]\-\-version\f[]
Print version information and exit.
.RS
.RE
.TP
.B \f[B]\-W\f[] \f[I]NUM\f[],\ \f[B]\-\-wiki\-link\-count=NUM\f[]
For TTY output, show \f[I]NUM\f[] wiki links to more information about
mentioned warnings.
Set to 0 to disable them entirely.
.RS
.RE
.TP
.B \f[B]\-x\f[],\ \f[B]\-\-external\-sources\f[]
Follow \[aq]source\[aq] statements even when the file is not specified
as input.
By default, \f[C]shellcheck\f[] will only follow files specified on the
command line (plus \f[C]/dev/null\f[]).
This option allows following any file the script may \f[C]source\f[].
.RS
.RE
.TP
.B \f[B]FILES...\f[]
One or more script files to check, or "\-" for standard input.
.RS
.RE
.SH FORMATS
.TP
.B \f[B]tty\f[]
Plain text, human readable output.
This is the default.
.RS
.RE
.TP
.B \f[B]gcc\f[]
GCC compatible output.
Useful for editors that support compiling and showing syntax errors.
.RS
.PP
For example, in Vim,
\f[C]:set\ makeprg=shellcheck\\\ \-f\\\ gcc\\\ %\f[] will allow using
\f[C]:make\f[] to check the script, and \f[C]:cnext\f[] to jump to the
next error.
.IP
.nf
\f[C]
<file>:<line>:<column>:\ <type>:\ <message>
\f[]
.fi
.RE
.TP
.B \f[B]checkstyle\f[]
Checkstyle compatible XML output.
Supported directly or through plugins by many IDEs and build monitoring
systems.
.RS
.IP
.nf
\f[C]
<?xml\ version=\[aq]1.0\[aq]\ encoding=\[aq]UTF\-8\[aq]?>
<checkstyle\ version=\[aq]4.3\[aq]>
\ \ <file\ name=\[aq]file\[aq]>
\ \ \ \ <error
\ \ \ \ \ \ line=\[aq]line\[aq]
\ \ \ \ \ \ column=\[aq]column\[aq]
\ \ \ \ \ \ severity=\[aq]severity\[aq]
\ \ \ \ \ \ message=\[aq]message\[aq]
\ \ \ \ \ \ source=\[aq]ShellCheck.SC####\[aq]\ />
\ \ \ \ ...
\ \ </file>
\ \ ...
</checkstyle>
\f[]
.fi
.RE
.TP
.B \f[B]diff\f[]
Auto\-fixes in unified diff format.
Can be piped to \f[C]git\ apply\f[] or \f[C]patch\ \-p1\f[] to
automatically apply fixes.
.RS
.IP
.nf
\f[C]
\-\-\-\ 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\ \[aq]Playlist\ $f\ contains\ a\ HQ\ file\ in\ mp3\ format\[aq]
\ done
\f[]
.fi
.RE
.TP
.B \f[B]json1\f[]
Json is a popular serialization format that is more suitable for web
applications.
ShellCheck\[aq]s json is compact and contains only the bare minimum.
Tabs are counted as 1 character.
.RS
.IP
.nf
\f[C]
{
\ \ comments:\ [
\ \ \ \ {
\ \ \ \ \ \ "file":\ "filename",
\ \ \ \ \ \ "line":\ lineNumber,
\ \ \ \ \ \ "column":\ columnNumber,
\ \ \ \ \ \ "level":\ "severitylevel",
\ \ \ \ \ \ "code":\ errorCode,
\ \ \ \ \ \ "message":\ "warning\ message"
\ \ \ \ },
\ \ \ \ ...
\ \ ]
}
\f[]
.fi
.RE
.TP
.B \f[B]json\f[]
This is a legacy version of the \f[B]json1\f[] format.
It\[aq]s a raw array of comments, and all offsets have a tab stop of 8.
.RS
.RE
.TP
.B \f[B]quiet\f[]
Suppress all normal output.
Exit with zero if no issues are found, otherwise exit with one.
Stops processing after the first issue.
.RS
.RE
.SH DIRECTIVES
.PP
ShellCheck directives can be specified as comments in the shell script.
If they appear before the first command, they are considered file\-wide.
Otherwise, they apply to the immediately following command or block:
.IP
.nf
\f[C]
#\ shellcheck\ key=value\ key=value
command\-or\-structure
\f[]
.fi
.PP
For example, to suppress SC2035 about using \f[C]\&./*.jpg\f[]:
.IP
.nf
\f[C]
#\ shellcheck\ disable=SC2035
echo\ "Files:\ "\ *.jpg
\f[]
.fi
.PP
To tell ShellCheck where to look for an otherwise dynamically determined
file:
.IP
.nf
\f[C]
#\ shellcheck\ source=./lib.sh
source\ "$(find_install_dir)/lib.sh"
\f[]
.fi
.PP
Here a shell brace group is used to suppress a warning on multiple
lines:
.IP
.nf
\f[C]
#\ shellcheck\ disable=SC2016
{
\ \ echo\ \[aq]Modifying\ $PATH\[aq]
\ \ echo\ \[aq]PATH=foo:$PATH\[aq]\ >>\ ~/.bashrc
}
\f[]
.fi
.PP
Valid keys are:
.TP
.B \f[B]disable\f[]
Disables a comma separated list of error codes for the following
command.
The command can be a simple command like \f[C]echo\ foo\f[], or a
compound command like a function definition, subshell block or loop.
.RS
.RE
.TP
.B \f[B]enable\f[]
Enable an optional check by name, as listed with
\f[B]\-\-list\-optional\f[].
Only file\-wide \f[C]enable\f[] directives are considered.
.RS
.RE
.TP
.B \f[B]source\f[]
Overrides the filename included by a \f[C]source\f[]/\f[C]\&.\f[]
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
\f[C]/dev/null\f[].
.RS
.RE
.TP
.B \f[B]source\-path\f[]
Add a directory to the search path for \f[C]source\f[]/\f[C]\&.\f[]
statements (by default, only ShellCheck\[aq]s working directory is
included).
Absolute paths will also be rooted in these paths.
The special path \f[C]SCRIPTDIR\f[] can be used to specify the currently
checked script\[aq]s directory, as in \f[C]source\-path=SCRIPTDIR\f[] or
\f[C]source\-path=SCRIPTDIR/../libs\f[].
Multiple paths accumulate, and \f[C]\-P\f[] takes precedence over them.
.RS
.RE
.TP
.B \f[B]shell\f[]
Overrides the shell detected from the shebang.
This is useful for files meant to be included (and thus lacking a
shebang), or possibly as a more targeted alternative to
\[aq]disable=2039\[aq].
.RS
.RE
.SH RC FILES
.PP
Unless \f[C]\-\-norc\f[] is used, ShellCheck will look for a file
\f[C]\&.shellcheckrc\f[] or \f[C]shellcheckrc\f[] in the script\[aq]s
directory and each parent directory.
If found, it will read \f[C]key=value\f[] pairs from it and treat them
as file\-wide directives.
.PP
Here is an example \f[C]\&.shellcheckrc\f[]:
.IP
.nf
\f[C]
#\ Look\ for\ \[aq]source\[aq]d\ files\ relative\ to\ the\ checked\ script,
#\ and\ also\ look\ for\ absolute\ paths\ in\ /mnt/chroot
source\-path=SCRIPTDIR
source\-path=/mnt/chroot
#\ 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\ using\ `which`\ since\ it\ gives\ full\ paths\ and\ is\ common\ enough
disable=SC2230
\f[]
.fi
.PP
If no \f[C]\&.shellcheckrc\f[] is found in any of the parent
directories, ShellCheck will look in \f[C]~/.shellcheckrc\f[] followed
by the XDG config directory (usually \f[C]~/.config/shellcheckrc\f[]) on
Unix, or \f[C]%APPDATA%/shellcheckrc\f[] on Windows.
Only the first file found will be used.
.PP
Note for Snap users: the Snap sandbox disallows access to hidden files.
Use \f[C]shellcheckrc\f[] without the dot instead.
.PP
Note for Docker users: ShellCheck will only be able to look for files
that are mounted in the container, so \f[C]~/.shellcheckrc\f[] will not
be read.
.SH ENVIRONMENT VARIABLES
.PP
The environment variable \f[C]SHELLCHECK_OPTS\f[] can be set with
default flags:
.IP
.nf
\f[C]
export\ SHELLCHECK_OPTS=\[aq]\-\-shell=bash\ \-\-exclude=SC2016\[aq]
\f[]
.fi
.PP
Its value will be split on spaces and prepended to the command line on
each invocation.
.SH RETURN VALUES
.PP
ShellCheck uses the follow exit codes:
.IP \[bu] 2
0: All files successfully scanned with no issues.
.IP \[bu] 2
1: All files successfully scanned with some issues.
.IP \[bu] 2
2: Some files could not be processed (e.g.
file not found).
.IP \[bu] 2
3: ShellCheck was invoked with bad syntax (e.g.
unknown flag).
.IP \[bu] 2
4: ShellCheck was invoked with bad options (e.g.
unknown formatter).
.SH LOCALE
.PP
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.
\f[C]LC_CTYPE\f[] is respected for output, and defaults to UTF\-8 for
locales where encoding is unspecified (such as the \f[C]C\f[] locale).
.PP
Windows users seeing
\f[C]commitBuffer:\ invalid\ argument\ (invalid\ character)\f[] should
set their terminal to use UTF\-8 with \f[C]chcp\ 65001\f[].
.SH AUTHORS
.PP
ShellCheck is developed and maintained by Vidar Holen, with assistance
from a long list of wonderful contributors.
.SH REPORTING BUGS
.PP
Bugs and issues can be reported on GitHub:
.PP
https://github.com/koalaman/shellcheck/issues
.SH COPYRIGHT
.PP
Copyright 2012\-2019, Vidar Holen and contributors.
Licensed under the GNU General Public License version 3 or later, see
https://gnu.org/licenses/gpl.html
.SH SEE ALSO
.PP
sh(1) bash(1)