For some reason this script prints “string are equal”
#!/bin/bash
A='foo'
B='bar'
if [ $A=$B ];
then
echo 'strings are equal'
fi
What am I doing wrong?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You have to leave a space around the equal sign:
Edit: Please notice also the quotation marks around the variables. Without them you will get into trouble if one of them is empty.
Otherwise the test is interpreted as test if the string “foo=bar” has a length>0.
See
man test: