SC2335 – ShellCheck Wiki

See this page on GitHub

Sitemap


Use [ "$var" -ne 1 ] instead of [ ! "$var" -eq 1 ]

and other binary operators such as

Problematic code:

if [ ! "$var" -eq 1 ]; then :; fi
if ! [ "$var" = foo ]; then :; fi

Correct code:

if [ "$var" -ne 1 ]; then :; fi
if [ "$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:


ShellCheck is a static analysis tool for shell scripts. This page is part of its documentation.