Skip to content
Joachim Ansorg edited this page Nov 12, 2021 · 2 revisions

Use [ x = y ] to compare values (or quote '==' if literal).

Problematic code:

if $var == value
then
  echo "Match"
fi

Correct code:

if [ "$var" = value ]
then
  echo "Match"
fi

Rationale:

ShellCheck found an unquoted == after a word.

This was most likely supposed to be a comparison, so use square brackets as in the correct code.

Exceptions:

If the == was supposed to be literal, you can quote it to make ShellCheck ignore it:

grep '===' file.js

Related resources:

  • Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!

ShellCheck

Each individual ShellCheck warning has its own wiki page like SC1000. Use GitHub Wiki's "Pages" feature above to find a specific one, or see Checks.

Clone this wiki locally