KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I tried the following script: #!/bin/bash var1="Test 1" var2="Test 2" if [ "$var1"="$var2" ] then echo "Equal" else echo "Not equal" fi It gave me Equal . Although it should have printed Not equal Only when I inserted space around = it worked as intended: if [ "$var1" = "$var2" ] and printed Not equal Why is it so? Why is "$var1"="$var2" not same as "$var1" = "$var2" ? Moreover, when I wrote if [ "$var1"= "$var2" ] , it gave line 4: [: Test 1=: unary operator expected What does it mean? How come it's expecting a unary operator?
Tags (comma-separated)
Save Edits
Cancel