test-exit-status
What it does
Section titled “What it does”Reports a test that compares $? with a number, as in [ $? -eq 0 ].
Why it matters
Section titled “Why it matters”if cmd already tests the status. A separate test of $? is one more line, and $? is changed by any command that runs in between.
To fix, test the command: if cmd; then.
Example
Section titled “Example”if [ $? -eq 0 ]; then :; fiif [ "$?" != 0 ]; then :; fi[ $x -eq 0 ]...[ -a file ]...Configuration
Section titled “Configuration”shell: lint: rules: test-exit-status: warn # off (default), warn, errorEnabled by the presets: shell/shellcheck.
Suppress one line with sudsy-disable-next-line test-exit-status in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.
| Tool | Rule | Match | What differs |
|---|---|---|---|
| shellcheck | SC2181 |
partial | Only [ ]/[[ ]] tests that compare $? directly. |