Reputation: 298
Compare $string
and "$string"
:
string="xx yy zz"
if [[ $string == "$string" ]]; then
echo "Strings are equal."
else
echo "Strings are not equal."
fi
We get:Strings are equal.
set -- $string
echo $#
3
To set arguments with $string
get 3 arguments.
set -- "$string"
echo $#
1
To set arguments with "$string"
get 1 argument.
What result in this difference?
Upvotes: -1
Views: 85
Reputation: 141698
This difference results because [[
is super very very magic. it is a syntatic sugar in bash handled when parsing the input, not a real command. Inside [[
qoutes have slightly different meaning depending on context. In the case of == , qoutes can be omited, so the strings are equal.
In contrast, the [
or test
is a normal command. You can check how the following fails:
[ $string == "$string" ]
Upvotes: 1