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

Re: sh compatibility issue



On Tue, Feb 22, 2011 at 08:02:59PM +0000, Peter Stephenson wrote:
> On Sun, 20 Feb 2011 16:39:29 -0500
> Chet Ramey <chet.ramey@xxxxxxxx> wrote:
> > On 2/20/11 2:11 PM, Peter Stephenson wrote:
> > >> 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.
> > > 
> > > I think it does need to be fatal, but not because it's a special builtin
> > > --- it looks like that's only a "may" rather than a "shall" --- but
> > > because there is a rule for exec:
> > 
> > No, that's actually a `shall'.  Section 2.8.1, special builtin, redirection
> > error.
> 
> Thanks, didn't follow the link... it looks like the "may" here means
> "may be required to".  The table shows essentially all errors for
> special builtins are fatal.
> 
> I didn't actually test for a special builtin in the previous patch,
> either.  Here's a revised patch with more careful tests.

I don't think it worked.  With this patch added, the bahaviour did not
change from the previous patch.  Fatal error in sh mode not not in zsh
mode.

    $ /usr/bin/zsh -c 'exec </nonexistent/a; echo wrong'
    zsh:1: no such file or directory: /nonexistent/a
    wrong
    
    $ /usr/bin/zsh -c 'emulate sh; exec </nonexistent/a; echo wrong'
    zsh:1: no such file or directory: /nonexistent/a



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