To ignore a ShellCheck error, you can do one of three things:
Use a directive to disable a certain instance:
hexToAscii() {
# shellcheck disable=SC2059
printf "\x$1"
}
You can pass multiple errors to directive:
# shellcheck disable=SC2116,SC2086
hash=$(echo ${hash}) # trim spaces
Use a -e
flag to disable a specific error when running
shellcheck
:
$ shellcheck -e SC2059 myscript
As of v0.7.0 you can create a file .shellcheckrc
in your
home directory (or your project's base directory), and add
disable
directives to it:
# ~/.shellcheckrc
disable=SC2059,SC2034 # Disable individual error codes
disable=SC1090-SC1100 # Disable a range of error codes
In earlier versions, you can set the environment variable
SHELLCHECK_OPTS
in your .bashrc
,
/etc/profile
or equivalent:
export SHELLCHECK_OPTS="-e SC2059 -e SC2034 -e SC1090"
Pass it to Docker directly:
docker run -e SHELLCHECK_OPTS="-e SC2059 -e SC2034 -e SC1090" -v "$PWD:/mnt" koalaman/shellcheck myscript
Optionally you can set the SHELLCHECK_OPTS
variable in
shell:
export SHELLCHECK_OPTS="-e SC2059 -e SC2034 -e SC1090"
and then pass it to Docker:
docker run -e SHELLCHECK_OPTS -v "$PWD:/mnt" koalaman/shellcheck myscript
Add a directive at the top of the file:
#!/bin/sh
# shellcheck disable=SC2059
Note that the directive must be on the first line after the shebang with versions before 0.4.6. As of 0.4.6 comments and whitespace are allowed before file-wide directives.
Add a directive at the top of the file:
#!/bin/sh
# shellcheck disable=all
Note that the directive must be on the first non-commented/non-whitespace line after the shebang with versions after 0.4.6.
ShellCheck is a static analysis tool for shell scripts. This page is part of its documentation.