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

What is ShellCheck and how do you use it in a team?

BeginnerConceptShellCheck, debugging, testing, portability and security
Answer

ShellCheck is a static analyzer for shell scripts that catches quoting bugs, unchecked cd, unused variables, portability problems and dozens of subtle errors, each with a code (SC2086) and a wiki page.

shellcheck -x deploy.sh lib/*.sh           # -x follows `source`d files
shellcheck -s sh entrypoint.sh             # check as POSIX sh
shellcheck -S warning scripts/*.sh         # minimum severity
shellcheck -f gcc scripts/*.sh             # editor/CI friendly format

We run it in pre-commit and CI with zero findings allowed, and in editors via the VS Code extension.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on ShellCheck, debugging, testing, portability and security