Please let me know what is error am I doing here. I am getting this output irrespective of the values of a and b variables.
CodePudding user response:
You have to rewrite [ $a == $b]
to [ $a == $b ]
.
CodePudding user response:
Strictly speaking, == is used to compare strings. You'd like to use -eq to compare integer values. In the following example string comparison will fail even if integer value is the same:
a=010
b=10
if [ $a == $b ] ; then
echo "A == B"
else
echo "A <> B"
fi
But if we change test operate to -eq
a=010
b=10
if [ $a -eq $b ] ; then
echo "A == B"
else
echo "A <> B"
fi
Result will be A == B