Both = and == are operators. In some languages (like C) one is used to assign a value to a variable and the other to compare values (result of arithmetic expressions). In fact, both operators are exactly that inside Arithmetic Evaluation. A $((a=23)) is an assignment, a $((a==23)) is an Arithmetic Comparison.
$ echo "$((a=11)) $((a==23))" "$((a=23))" "$((a==23))"
11 0 23 1
But inside test constructs (all of test and […] and [[…]]) both operators are intended to mean the same and perform the same operation.
So, all of this options:
test "$a" = "$b"
[ "$a" = "$b" ]
[[ "$a" = "$b" ]]
test "$a" == "$b"
[ "$a" == "$b" ]
[[ "$a" == "$b" ]]
Are equivalent inside bash to test binary equality (variables quoted). If the right variable is unquoted it may be interpreted as a pattern and matched accordingly: as a pattern not as a literal string.
The quoted operators \= and \== are also equivalent when used in test and […]. But the quoted operator \== fails inside [[…]].
For other shells the results are varied (correct result should be Y - (true false), an exit code different from 0 (true) and 1 (false) is reported as failure wih ¤). Some shells fail with - - (the exit code is always 1).
| dash ksh bash zsh
test a = "$b" | Y - Y - Y - Y -
[ a = "$b" ] | Y - Y - Y - Y -
[[ a = "$b" ]] | ¤ ¤ Y - Y - Y -
test a == "$b" | ¤ ¤ Y - Y - - -
[ a == "$b" ] | ¤ ¤ Y - Y - - -
[[ a == "$b" ]] | ¤ ¤ Y - Y - Y -
test a \= "$b" | Y - Y - Y - Y -
[ a \= "$b" ] | Y - Y - Y - Y -
[[ a \= "$b" ]] | ¤ ¤ Y - - - - -
test a \== "$b" | ¤ ¤ Y - Y - Y -
[ a \== "$b" ] | ¤ ¤ Y - Y - Y -
[[ a \== "$b" ]] | ¤ ¤ Y - - - - -
All options work in ksh, quoted operators fail in bash and zsh (inside [[…]]) and the unquoted \= and \== also fail in zsh (outside of [[…]]).
though some [ implementations also recognise ==ahhh thanks for that! Bash was succeeding but zsh failing on[ $x == $y ]. Both shells accepted double-bracket+double-equals OR single-bracket+single-equals, but only bash allowed the mixed POSIX first scenario – xref May 20 '21 at 23:22zsh's[builtin does support the==operator, but there, the=cmdoperator interferes with it. See edit. – Stéphane Chazelas May 21 '21 at 05:11