cc: [email protected]
Subject: Re: [ast-users] errexit and exec/command exec weirdness
--------
> Hi
>
> Excerpt from the manual:
> /--/
> For example, the predefined alias redirect='command exec' prevents a
> script from terminating when an invalid redirection is given.
> /--/
>
> The following happens under x86_64 Linux (SLES), but also happens under
> old FreeBSD 4-STABLE with Version M 1993-12-28 r.
>
> $ print ${.sh.version}
> Version JM 93t+ 2009-06-30
> $ ls -la jura.log
> -rw-r--r-- 1 root root 0 10. nov 12:53 jura.log
> $ id
> uid=XXX(vallo) gid=XXX(users)
> $ set +e
> $ exec 3>jura.log
> ksh: jura.log: cannot create [Permission denied]
> $ redirect 3>jura.log
> ksh: jura.log: cannot create [Permission denied]
> $ set -e
> $ exec 3>jura.log
> ksh: jura.log: cannot create [Permission denied]
> $ redirect 3>jura.log
> ksh: jura.log: cannot create [Permission denied]
> myhakas:vallo$ echo $?
> 1
>
> Reading the manual it seems that failing redirection using special
> builtin exec should abort the shell. This is not happening. What's more
> weird in second case with set -e the redirect aborts the shell.
> Am I reading it backwards or what?
> --
> Vallo Kallaste
With set -e, a shell should terminate whenever a command not
part of a conditional (or a few other special cases) whether it
is interactive. Thus, for an interactive shell,
$ set -e
$ exec 3> /non/xxx
should have caused this shell to fail and this will be fixed.
Similarly for redirect, (command exec).
However,
set -e
command exec 3> /non/xxx || print failure
will not cause the shell to exit where as
set -e
exec 3> /non/xxx || print failure
will (at least for a non-interactive shell until the bug fix).
Also, within a script without set -e,
exec 3> /non/xxx
will cause the script to fail whereas
command exec 3> /non/xxx
will not.
David Korn
[email protected]
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users