bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: comparison inside [[]] is not numeric comparison?


From: DennisW
Subject: Re: comparison inside [[]] is not numeric comparison?
Date: Wed, 08 Dec 2010 15:53:20 -0000
User-agent: G2/1.0

On Nov 19, 6:45 pm, "john.ruckstuhl" <john.ruckst...@gmail.com> wrote:
> In bash, a comparison inside "[["/"]]" is lexicographic not numeric?
> This isn't what I expected.
> Which part of the documentation would set me straight?  If someone
> could quote the fine manual, that would be great.
>
> $ if [[ 2000 > 200 ]]; then echo pass; else echo wierd; fi
> pass
>
> $ if [[ 1000 > 200 ]]; then echo pass; else echo wierd; fi
> wierd
>
> $ set | grep BASH_VERSION
> BASH_VERSION='3.2.51(24)-release'
>
> Thanks,
> John R.


To do numeric comparison within double square brackets, use -gt, for
example.

To do numeric comparisons using operators such as >, do them inside
double parentheses.

[[ 10 > 2]]     # false
[[ 10 -gt 2 ]]  # true
(( 10 > 2 ))    # true


In the man page under CONDITIONAL EXPRESSIONS:

string1 < string2
              True if string1 sorts before string2  lexicographically
in  the
              current locale.

string1 > string2
              True  if  string1  sorts  after string2
lexicographically in the
              current locale.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]