Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: sh compatibility issue
On Sun, Feb 20, 2011 at 12:05:40AM +0100, Jilles Tjoelker wrote:
> > !(...) without space
>
> I think the POSIX spec requires this to work, but that may not be
> intentional. '(' is an operator and therefore it does not need a space
> between it and other characters (except to disambiguate between two
> adjacent operators and one two-character operator). It may not be
> intentional because it conflicts with ksh extended pattern matching.
>
> More generally, this rule also means that things like
> while(true)do(pwd)done
> do not need any spaces. Although this example is contrived, I can
> imagine there are real scripts that zsh fails to parse because of this;
> the other shells I tried execute it correctly.
>
> The situation for '!{' is different. '{' is a reserved word and
> therefore it is not recognized. Instead, this describes a utility (or
> alias) that probably does not exist. I do not recommend making special
> allowances for it.
>
> On a related note, here is another quite insidious sh compatibility
> issue:
> sh -c 'exec </nonexistent/a; echo wrong'
> This should not print "wrong" because exec is a special builtin and
> redirection errors on special builtins are fatal. Most shells get this
> right nowadays (bash only in POSIX mode) but zsh gets it wrong. Even
> set -o posixbuiltins
> does not help.
>
> --
> Jilles Tjoelker
Interesting.
I ran these two tests tests with sh, ksh, bash, and zsh.
while(true)do(pwd)done
This worked in sh, ksh, and bash. It failed only in zsh.
sh -c 'exec </nonexistent/a; echo wrong'
This did not print "wrong" in sh and ksh.
Zsh prints wrong in both sh and zsh mode and bash only prints "wrong"
without the --posix switch.
Vince
Messages sorted by:
Reverse Date,
Date,
Thread,
Author