and-or-is-not-if-else
What it does
Section titled “What it does”Reports a list a && b || c of three commands, unless c is echo, printf, true, :, return or exit.
Why it matters
Section titled “Why it matters”It looks like an if/else, but c runs whenever a && b does not succeed, and that includes the case where a succeeds and b fails. A failing b runs both b and c.
To fix, write an if a; then b; else c; fi.
Example
Section titled “Example”...test -f x && echo yes || cleanuptest -f x && echo yes || echo no[ -n x ] && (a || b)a && b...Configuration
Section titled “Configuration”shell: lint: rules: and-or-is-not-if-else: warn # off (default), warn, errorEnabled by the presets: shell/shellcheck.
Suppress one line with sudsy-disable-next-line and-or-is-not-if-else 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 | SC2015 |
partial | Only the plain three-command list; shellcheck exempts a true/: middle command. |