On Sat, Mar 04, 2017 at 01:15:58PM +0100, Rob la Lau wrote:
> Looking a bit further: it doesn't do any comparison on the given strings:
> 
> $ [[ "x" -eq "y" ]] && echo "yes" || echo "no"
> yes

You're misunderstanding.  In a math context, which you are creating here
by using -eq, the word 'x' is interpreted as a variable name, which may
contain another variable name, and so on, until finally an integer is
discovered.  Same for the word 'y'.

> $ [[ "x" -eq "yz" ]] && echo "yes" || echo "no"
> yes

Same for the word 'yz'.

In your case, I suspect the variables x, y and yz are all undefined, which
means they evaluate to 0.

imadev:~$ unset x yz; if [[ x -eq yz ]]; then echo yes; else echo no; fi
yes
imadev:~$ x=3 yz=foo foo=3; if [[ x -eq yz ]]; then echo yes; else echo no; fi
yes
imadev:~$ x=3 yz=foo foo=2; if [[ x -eq yz ]]; then echo yes; else echo no; fi
no

Reply via email to