bash string equality

brianegge picture brianegge · Jul 16, 2010 · Viewed 121.5k times · Source

In bash, what's the difference, if any, between the equal and double equal test operators?

[[ "a" = "a" ]] && echo equal || echo not-equal
[[ "a" == "a" ]] && echo equal || echo not-equal
[[ "a" = "b" ]] && echo equal || echo not-equal
[[ "a" == "b" ]] && echo equal || echo not-equal

results in:

equal
equal
not-equal
not-equal

Answer

schnaader picture schnaader · Jul 16, 2010

There's no difference, == is a synonym for = (for the C/C++ people, I assume). See here, for example.

You could double-check just to be really sure or just for your interest by looking at the bash source code, should be somewhere in the parsing code there, but I couldn't find it straightaway.