The following script does not behave as I would have expected.  Adding spaces around the '=' in the conditional made it perform how I wanted, but it got me thinking, what is it actually doing inside the conditional?#!/bin/bashS1='foo'S2='bar'if [ $S1=$S2 ];then    echo S1('$S1') is equal to S2('$S2')fiecho $S1echo $S2The output is:S1('foo') is equal to S2('bar')foobarThe contents of S1 and S2 don't change from what they are assigned, so the = doesn't perform an assignment.
How does bash interpret the equal operator with no surrounding spaces in a conditional?
bash;shell;scripting
It's helpful to remember that [ is actually a command, usually also available as test. In bash, it's a builtin, so you can see the documentation with man builtin.In that documentaiton:          test and [ evaluate conditional expressions using a set of rules          based on the number of arguments.          0 arguments                 The expression is false.          1 argument                 The expression is true if and only if the argument is not                 null.          2 arguments                 [...]          3 arguments                 [...]The two-argument rules are various tests, and the three-argument ones are generally comparisons. When you put a space around the =, you get three arguments. But when you put it all together, you get one argument, and as you can see, if that argument isn't null, it returns true.