I tried the following script
#!/bin/bash
var1=\"Test 1\"
var2=\"Test 2\"
if [ \"$var1\"=\"$var2\" ]
then
echo \"Equal\"
else
echo \"Not equa
When the shell reads
if [ "$var1" = "$var2" ]
it invokes the command [ with 4 arguments. Whether [ is a builtin or an external command is irrelevant, but it may help to understand that it may be the external command /bin/[. The second argument is the literal '=' and the fourth is ']'. However, when the shell reads
if [ "$var1"= "$var2" ]
[ only gets 3 arguments: the expansion of $var1 with '=' appended, the expansion of $var2, and ']'. When it gets only 3 arguments, it expects the last argument to be ']' and the first argument to be a unary operator.