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.
More on ShellCheck, debugging, testing, portability and security
How do you disable a ShellCheck warning, and when is that acceptable?IntermediateName 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