Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [[ and [



On Wed, Mar 07, 2012, Mikael Magnusson wrote about "Re: [[ and [":
> > On Tue, Mar 06, 2012, Mikael Magnusson wrote about "Re: [[ and [":
> >> Incidentally, this is probably the most confusing error message ever,
> >> % [ $foo == "" ]
> >> zsh: = not found
> >
> > I see something slightly different. On zsh 4.3.15, with unset $foo, I
>..
> You need to not have done unsetopt equals to see the confusing one :).

Wow, it's not just EQUALS (which I do have set, and use it all the time),
it's also the NOMATCH option which I forgot was the default. I've mentioned
this in the past that I think that NONOMATCH should be the default...
With NONOMATCH, I get:

$ echo =ls
/bin/ls
$ echo =dog
=dog
$ echo ==  
==
$ [ a == a ] && echo success
success

which is exactly what I would expect. With the (unfortunately default)
NOMATCH, I get:

$ echo =ls
/bin/ls
$ echo =dog
zsh: dog not found
$ echo ==
zsh: = not found
$ [ a == a ] && echo success
zsh: = not found

So the confusing error doesn't come from [, it comes from NOMATCH, which
(did I say that? :-)) I really don't like being the default.

One thing to note, though, is that the traditional equality operator for
test (or '[') was "=", not "==", so had you used =, you would not have
this problem in the first place...


-- 
Nadav Har'El                        |                  Wednesday, Mar 7 2012, 
nyh@xxxxxxxxxxxxxxxxxxx             |-----------------------------------------
Phone +972-523-790466, ICQ 13349191 |Topologist, n.: A person who cannot tell
http://nadav.harel.org.il           |a doughnut from a coffee mug.



Messages sorted by: Reverse Date, Date, Thread, Author