help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] [[ " 123 " -eq 123 ]] is supposed to work?


From: Greg Wooledge
Subject: Re: [Help-bash] [[ " 123 " -eq 123 ]] is supposed to work?
Date: Mon, 9 Feb 2015 08:31:37 -0500
User-agent: Mutt/1.4.2.3i

On Mon, Feb 09, 2015 at 11:19:15AM +0800, Clark Wang wrote:
> I found some people often use this syntax

Presumably you mean this, from the Subject: header:

[[ " 123 " -eq 123 ]]

> to avoid manually removing the
> leading and trailing spaces. I never use this as I'm not sure if it's a
> standard feature. So is this feature documented?

Probably not documented as such (I don't see anything about it in the
ARITHMETIC EVALUATION section).  It's just a general side effect of how a
math context works.  You don't need to use the [[ -eq ]] version, either.
You can use the more typical ((...)) version:

imadev:~$ if (( " 123 " == 123 )); then echo yes; fi
yes

Or more likely, you mean something like this:

imadev:~$ x=" 123 "; if ((x == 123)); then echo yes; fi
yes



reply via email to

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