ssb
ssb

Reputation: 209

compared two parameters using "<" in shell

let's assign like this:

a=7
b=29
[[ $a < $b ]] && echo dasf

it doesn't work!!

however, when

a=1

with b and command same, it works well.

That's very funky! Can somebody explain that?

Upvotes: 1

Views: 66

Answers (1)

Adam Liss
Adam Liss

Reputation: 48310

You're comparing the variables lexically, not numerically.

Try

[[ $a -lt $b ]] && echo smaller

or

(( $a < $b )) && echo smaller

Upvotes: 3

Related Questions