SC2276 – ShellCheck Wiki

See this page on GitHub

Sitemap


This is interpreted as a command name containing =. Bad assignment or comparison?

Problematic code:

"$var"=42
if "$var"=42
then
  true
fi

Correct code:

var=42
if [ "$var" = 42 ]
then
  true
fi

Rationale:

ShellCheck found a command name containing an unquoted equals sign =. This was likely intended as either a comparison or an assignment.

To compare two values, use e.g. [ "$var" = "42" ]

To assign a value, use e.g. var="42"

Exceptions:

None, though you can quote the = to make ShellCheck ignore it: "$var=42".


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