Interview Prep/Shell Scripting/ShellCheck, debugging, testing, portability and security

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/.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on ShellCheck, debugging, testing, portability and security