[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] [[ " 123 " -eq 123 ]] is supposed to work?
From: |
Clark Wang |
Subject: |
Re: [Help-bash] [[ " 123 " -eq 123 ]] is supposed to work? |
Date: |
Tue, 10 Feb 2015 15:23:05 +0800 |
Thanks, Greg. I just wanted to confirm if it's officially documented.
Personally I don't like to use undocumented features. :)
-clark
On Mon, Feb 9, 2015 at 9:31 PM, Greg Wooledge <address@hidden> wrote:
> 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
>