What is the difference between =
and ==
to compare strings in Linux shell programming?
Maybe the following code works:
if [ "$NAME" = "user" ]
then
echo "your name is user"
fi
But I think it's not a correct syntax. It would be used to compare string by ==
statement.
What is correct?
The single equal is correct
In general, the = operator works the same as == when comparing strings.
Note: The == comparison operator behaves differently within a double-brackets test than within single brackets.
source: http://tldp.org/LDP/abs/html/comparison-ops.html
you can take a look here or here. Personally, to compare strings, I use
case
I do not have to know which operator i should use
These pages explain the various comparison operators in bash:
On the second linked page, you will find: