String comparison tutorial not helpful

I have a bash string comparison which is not working, looked for help, and found this.

   
= 
is equal to
if [ "$a" = "$b" ]
 
http://www.tldp.org/LDP/abs/images/caution.gifNote the whitespace framing the =.
if [ "$a"="$b" ] is not equivalent to the above.

</DIV>
I do not find this to be helpful because I am asked to note the whitespace framing the = but am not told what its significance is.

The code which is not working is:

  if ["$TWI_IP" = "$TWJ_IP"]
                 then
                     PRO=1
                      echo we got an EQUAL!!!!!
                 else
                      echo we did not get an equal even though they are equal
                 fi
    

The string variables TWI_IP and TWJ_IP have equal contents but this code will always take the else branch.

There should be a space between if and [ as well as a space between [ and "$TWI_IP"

if [ "$TWI_IP" = "$TWJ_IP" ]
then
  PRO=1
  echo we got an EQUAL!!!!!
else
  echo we did not get an equal even though they are equal
fi          

--ahamed

The significance is as follow:
First look at this : [ "$a"="$b" ]

The shell takes "$a", appends an "=" to it, and then it appends "$b" to it.
This is a single longer string containing an equal sign. There is no comparison evaluation done in this case. The only evaluation done is to check that the long string is not empty, which it will never be since there is always at least an equal sign in it even if both $a and $b are empty.

Second, take this:
[ "$a" = "$b" ]

The shell sees three strings: $a, and equal sign, and $b. The equal sign is interpreted as an operator and evaluated as you expect.

Hope this helps.

---------- Post updated at 07:49 AM ---------- Previous update was at 07:44 AM ----------

Extrapolate the same for the spaces between the [ ... ] and the arguments.

When the [ and ] is not separate (surrounded by spaces) then the shell do not recognize them as special characters.

Essentially you have
if "[$a" = "$b]"

Because the brackets are added to the strings before evaluation is done.