Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

bash input:

if [[ 167 > 10800 ]]
    echo "I can't compare"

bash output:

I can't compare

I guess the question is pretty obvious...

share|improve this question
I know the operator is -gt and -lt for [ and ]. I am not sure what [[ and ]] is. – Jul 21 '11 at 21:12
@slhck: Neither of them works, actually. – Mehrdad Jul 21 '11 at 21:19
@Mehrdad Neither of what? – slhck Jul 21 '11 at 21:22
@slhck: Single or double brackets. – Mehrdad Jul 21 '11 at 21:23
up vote 7 down vote accepted

To quote from the bash(1) manual page:

When used with [[, the < and > operators sort lexicographically using the current locale.

So 167 is indeed greater than 10800 as 6 is a greater ASCII character than 0.

share|improve this answer
OOOOHHHH facemonitor +1 – Mehrdad Jul 21 '11 at 21:21

The > character doesn't work for the type of comparison you want. You have to use -gt:

if [[ 167 -gt 10800 ]]
    echo "I can't compare"

And if you want to do a less-than comparison, you need to do -lt. To see what other options you need to do for comparison, look at the test manpage.

share|improve this answer
-1 I beg to differ. – Mehrdad Jul 21 '11 at 21:18
@Mehrdad: edited. – Wuffers Jul 21 '11 at 21:20
Interesting, +1... – Mehrdad Jul 21 '11 at 21:22

Use curved brackets for a true numeric comparison

if (( 167 > 10800 ))
    echo "I can't compare"

Good summary here:

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .