Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 29 Dec 1999 13:51:53 +0100 (CET)
From:      Oliver Fromme <olli@dorifer.heim3.tu-clausthal.de>
To:        freebsd-stable@FreeBSD.ORG
Subject:   Re: /bin/test broken ?
Message-ID:  <199912291251.NAA25219@dorifer.heim3.tu-clausthal.de>

next in thread | raw e-mail | index | archive | help
Peter Jeremy wrote in list.freebsd-stable:
 > Of course, that assumes that the shell doesn't have other
 > problems with its parsing:
 > 
 > $ zsh -c '[ 1 -ne 0 ] && echo correct' 
 > correct
 > $ zsh -c '/bin/[ 1 -ne 0 ] && echo correct' 
 > zsh: bad pattern: /bin/[
 > $
 > 
 > (Found by accident whilst looking into the original problem - I haven't,
 > but probably should, report it as a bug in zsh 3.0.5).

It's not a bug, it's a feature.  :)

By default, zsh handles ``['' as part of a glob expression.
And according to that behaviour,  ``/bin/['' _is_ a broken glob
expression, whether you like it or not (I happen to like it,
because it's more consistent and causes less surprises).
It's (intentionlly) not compatible with the bourne shell.
Look at the third example, please:

$ zsh -c '[ 1 -ne 0 ] && echo correct' 
correct
$ zsh -c '/bin/[ 1 -ne 0 ] && echo correct' 
zsh: bad pattern: /bin/[
$ zsh -c 'emulate sh ; /bin/[ 1 -ne 0 ] && echo correct'
[: ]: unexpected operator

The behaviour in the last example is the default when zsh is
invoked as ``sh''.  (I'm using zsh 3.0.7, but it works the same
in 3.0.5.)

For what it's worth, GNU test behaves similarly to ours:
$ /usr/local/bin/[ 1 -ne 0 ] && echo correct
/usr/local/bin/[: too many arguments

Regards
   Oliver

PS:  Instead of ``emulate sh'' or invoking it as ``sh'', you
can also modify the behaviour by zsh options (``setopt foo''),
see ``man zshoptions''.  In fact, ``emulate sh'' does nothing
more than performing a whole bunch of setopts to make zsh
behave like sh.  By default, zsh is not supposed to be 100%
sh-compatible.

-- 
Oliver Fromme, Leibnizstr. 18/61, 38678 Clausthal, Germany
(Info: finger userinfo:olli@dorifer.heim3.tu-clausthal.de)

"In jedem Stück Kohle wartet ein Diamant auf seine Geburt"
                                         (Terry Pratchett)


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-stable" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199912291251.NAA25219>