Skip to content
koalaman edited this page Apr 29, 2016 · 9 revisions

Shellcheck directives allows you to selectively ignore warnings, and takes the form of comments in files:

hexToAscii() {
  # shellcheck disable=SC2059
  printf "\x$1"
}

Supported directives are disable to disable warnings:

# shellcheck disable=code[,code...]
statement_where_warning_should_be_disabled

source to tell ShellCheck where to find a sourced file (since 0.4.0):

# shellcheck source=src/examples/config.sh
. "$(locate_config)"

shell, as a top level directive, to specify the shell for a script (similar to the shebang, if you for any reason don't want to add one) (since 0.4.4):

# shellcheck shell=sh
echo foo &> bar

Directives instead of or immediately after the shebang apply to the entire script. Otherwise, they are scoped to the structure that follows it (such as all branches of a case statement, or an entire function).

There is no support for scoping a directive to the first structure of the script. In these cases, use a dummy command true or : and then add directives, such as

# This directive applies to the entire script
# shellcheck disable=2086
true
# This directive only applies to this function
# shellcheck disable=2043
f() {
  ...
}

Silencing parser errors is purely cosmetic, and will not make ShellCheck continue.

Clone this wiki locally