From: Peter Stephenson <pws@ibmth.df.unipi.it>
To: Clint Adams <schizo@debian.org>,
zsh-workers@sunsite.auc.dk (Zsh hackers list)
Subject: PATCH: pws-18: ERR_EXIT behavior inconsistent with other shells
Date: Wed, 19 May 1999 11:44:05 +0200 [thread overview]
Message-ID: <9905190944.AA29055@ibmth.df.unipi.it> (raw)
In-Reply-To: "Clint Adams"'s message of "Mon, 17 May 1999 00:08:02 DFT." <19990517000802.A27319@dman.com>
Last thing on my to-do list before pws-19:
Clint Adams wrote:
> ARGV0=sh zsh -fexc 'testerrexit() { return 1; }; false || echo simplecommand;
> testerrexit || echo function'; echo $?
>
> does this
>
> + false
> + echo simplecommand
> simplecommand
> + testerrexit
> + return 1
> 1
>
> Other shells seems to do this
>
> ARGV0=sh ksh -fexc 'testerrexit() { return 1; }; false || echo simplecommand;
> te
> sterrexit || echo function'; echo $?
>
> + false
> + echo simplecommand
> simplecommand
> + testerrexit
> + echo function
> function
> 0
It took me a couple of minutes to work out the logic: any shell stuff which
is followed at any level of execution by a || or && should suppress errexit
until the final set of commands in the chain at the level at which the ||
or && appears. I originally thought that being in a function was turning
off errexit, but that's not it, and it should apply to { ... } structures
as well as functions (I checked this). I can't imagine this was anything
other than an oversight in the zsh code, since I don't suppose anybody ever
thought about it before. The following should make it consistent.
It also keeps it consistent with
% ksh -fec 'false || { false; print two; false; }; print three'
where you don't get the message `two' because in this case the shell exits
at the first `false' on the right. The rule seems to be `never exit on a
non-zero status left of a || or &&, always exit on the extreme right',
because you also get
% ksh -fec 'false && true; print yes'
yes
where zsh was already consistent with ksh.
--- Src/exec.c.ee Tue May 18 11:25:25 1999
+++ Src/exec.c Wed May 19 11:22:10 1999
@@ -697,6 +697,13 @@
static int donetrap;
int ret, cj;
int old_pline_level, old_list_pipe;
+ /*
+ * ERREXIT only forces the shell to exit if the last command in a &&
+ * or || fails. This is the case even if an earlier command is a
+ * shell function or other current shell structure, so we have to set
+ * noerrexit here if the sublist is not of type END.
+ */
+ int oldnoerrexit = noerrexit;
cj = thisjob;
old_pline_level = pline_level;
@@ -716,6 +723,8 @@
/* Loop through code followed by &&, ||, or end of sublist. */
while (slist) {
+ if (!oldnoerrexit)
+ noerrexit = (slist->type != END);
switch (slist->type) {
case END:
/* End of sublist; just execute, ignoring status. */
@@ -758,6 +767,8 @@
slist = slist->right;
}
sublist_done:
+
+ noerrexit = oldnoerrexit;
if (sigtrapped[SIGDEBUG])
dotrap(SIGDEBUG);
--
Peter Stephenson <pws@ibmth.df.unipi.it> Tel: +39 050 844536
WWW: http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy
prev parent reply other threads:[~1999-05-19 10:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-05-17 4:08 Clint Adams
1999-05-19 9:44 ` Peter Stephenson [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9905190944.AA29055@ibmth.df.unipi.it \
--to=pws@ibmth.df.unipi.it \
--cc=schizo@debian.org \
--cc=zsh-workers@sunsite.auc.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).