You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use [ "$var" -ne 1 ] instead of [ ! "$var" -eq 1 ]
and other binary operators such as
= and != (string)
-le and -gt, and so forth (arithmetic)
Optional - avoid-negated-conditions
This is an optional rule, which means that it has a special "long name" and is not enabled by default. See the optional page for more details. In short, you have to enable it with the long name instead of the "SC" code like you would with a normal rule:
.shellcheckrc
enable=avoid-negated-conditions # SC2335
Problematic code:
if [ !"$var"-eq 1 ];then:;fiif! [ "$var"= foo ];then:;fi
Correct code:
if [ "$var"-ne 1 ];then:;fiif [ "$var"!= foo ];then:;fi
Rationale:
Double negation of such binary operators is unnecessary.
Exceptions:
This is a stylistic issue that does not affect correctness. If you prefer the original expression, you can Ignore it with a directive or flag.
This rule is not applied to the followings:
< and > (lexicographical)
-nt and -ot (file timestamp)
=~ (regular expression)
Related resources:
Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!