How do you disable a ShellCheck warning, and when is that acceptable?
IntermediateConceptShellCheck, debugging, testing, portability and security
Answer
Disable it on the next line, with a reason, only when the code is intentionally doing what the warning describes:
# shellcheck disable=SC2086 # $OPTS is intentionally split into multiple flags
rsync $OPTS src/ dst/
Project-wide settings go in .shellcheckrc (disable=SC1091, source-path=SCRIPTDIR, external-sources=true). Disabling SC2086 globally to silence noise defeats the main reason to use ShellCheck. Often the better fix is an array: opts=(-a --delete); rsync "${opts[@]}" src/ dst/.
More on ShellCheck, debugging, testing, portability and security
What is ShellCheck and how do you use it in a team?BeginnerName the ShellCheck warnings you see most and what each means.IntermediateHow do you debug a Bash script?BeginnerHow do you make `set -x` output more useful with `PS4`?IntermediateWhat is bats, and how do you test a script that calls external commands?IntermediateWhat is `shfmt` and why use it alongside ShellCheck?Beginner