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: Greg Wooledge
Subject: Re: comparison inside [[]] is not numeric comparison?
Date: Thu, 9 Dec 2010 11:41:17 -0500
User-agent: Mutt/1.4.2.3i

On Fri, Nov 19, 2010 at 04:45:15PM -0800, john.ruckstuhl wrote:
> In bash, a comparison inside "[["/"]]" is lexicographic not numeric?

Correct.  Assuming you use the string-comparison operators (> and <)
rather than the integer-comparison operators (-gt, -lt, etc.).

> $ if [[ 1000 > 200 ]]; then echo pass; else echo wierd; fi
> wierd

String comparison.  If you want to do numeric comparisons, use ((...))
or use -gt.

if ((1000 > 200)); then echo pass; else echo weird; fi
if [[ 1000 -gt 200 ]]; then echho pass; else echo weird; fi



reply via email to

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