-
Notifications
You must be signed in to change notification settings - Fork 1.8k
SC2071
koalaman edited this page Nov 5, 2015
·
5 revisions
if [[ $var > 10 ]]
then
echo "Incorrectly triggers when var=5"
fi
if [[ $var -gt 10 ]]
then
echo "Correct numerical comparison"
fi
<
and >
, in both [[
and [
(when escaped) will do a lexicographical comparison, not a numerical comparison.
This means that [[ 5 > 10 ]]
is true because 5 comes after 10 alphabetically. Meanwhile [[ 5 -gt 10 ]]
is false because 5 does not come after 10 numerically.
If you want to compare numbers by value, use the numerical comparison operators -gt
, -ge
, -lt
and -le
.
None.