SC2181
The ShellCheck style note for running a command and then testing its status through the question-mark variable, instead of testing the command directly.
In more detail
if ! cd /nowhere; then is shorter and cannot be broken by another command slipping in between the command and the test.
Related terms
- ShellCheck — A linter for shell scripts that reports quoting mistakes, portability problems and common bugs, each with a numbered code.
- exit code — A number a process returns when it finishes: 0 means success, anything else means something went wrong.
- if statement — A statement that runs a block of code only when a condition holds, optionally with an else block for when it does not.
Taught in
- ShellCheck — Bash Scripting & Command Line Automation