Reputation: 1702
the following example shows hot to compare numbers I give here two different ways
one way with the ">" and "<" and second way with "-gt" or "-lt"
both ways are work exactly so what the differences between them ? or maybe there are not difference ?
example 1
ksh
a=1
b=2
[[ $a > $b ]] && echo ok
[[ $a < $b ]] && echo ok
ok
example 2
ksh
a=1
b=2
[[ $a -gt $b ]] && echo ok
[[ $a -lt $b ]] && echo ok
ok
Upvotes: 2
Views: 9759
Reputation: 362
In your examples there are no difference, but that is just an unfortunate choice of values for a and b.
-lt, -gt are for numeric comparison
< and > are for alphabetic comparison
$ a=12
$ b=6
$ [[ $a -lt $b ]] && echo ok
$ [[ $a < $b ]] && echo ok
ok
Upvotes: 3