Reputation: 159
x=23;
y=223;
if [[ $x < $y ]]
then
echo "TRUE"
else
echo "FALSE"
fi
So this always print FALSE even thought 23 is clearly less than 223. I am new to bash so I might be missing something obvious. I tried substituting $x and $y with their actually value and that means to work fine. Please send help
Upvotes: 1
Views: 18
Reputation: 781096
<
performs lexicographic ordering of strings. To get numeric ordering, use -lt
.
x=23;
y=223;
if [[ $x -lt $y ]]
then
echo "TRUE"
else
echo "FALSE"
fi
Or you can use an arithmetic expression instead of a conditional expression:
if (( $x < $y ))
Upvotes: 2