bash string equality

BashEqualsEquality

Bash Problem Overview


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

Bash Solutions


Solution 1 - Bash

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionbrianeggeView Question on Stackoverflow
Solution 1 - BashschnaaderView Answer on Stackoverflow