[ "$var" -ne 1 ]
instead of
[ ! "$var" -eq 1 ]
and other binary operators such as
=
and !=
(string)-le
and -gt
, and so forth
(arithmetic)if [ ! "$var" -eq 1 ]; then :; fi
if ! [ "$var" = foo ]; then :; fi
if [ "$var" -ne 1 ]; then :; fi
if [ "$var" != foo ]; then :; fi
Double negation of such binary operators is unnecessary.
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)-n
and -z
ShellCheck is a static analysis tool for shell scripts. This page is part of its documentation.