Re: [Help-bash] [[ " 123 " -eq 123 ]] is supposed to work?
From:
Eduardo A . Bustamante López
Subject:
Re: [Help-bash] [[ " 123 " -eq 123 ]] is supposed to work?
Date:
Sun, 8 Feb 2015 23:47:46 -0600
User-agent:
Mutt/1.5.23 (2014-03-12)
On Mon, Feb 09, 2015 at 11:19:15AM +0800, Clark Wang wrote:
> I found some people often use this syntax 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?
Yes, bash converts the string to a number to do the comparison. That means that
stuff like this works:
address@hidden:~$ [[ a -eq 0 ]]; echo $?
0