zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk (Zsh hackers list)
Subject: PATCH: exit status
Date: Fri, 10 Nov 2006 09:40:58 +0000	[thread overview]
Message-ID: <200611100940.kAA9ewZY012583@news01.csr.com> (raw)

A thread on the Austin group suggests the exit status of the shell
should be available in exit traps.  This is potentially useful,
particularly since there's no other way of getting the exit status.
It's hard to see how it can cause problems since previously the exit
status wasn't tied to any particular command (it was whatever happened
to run just before the exit) so didn't have a useful value inside the
trap.

There was one special case: on an implicit exit it always was and still
is the status of the last command before exit, however as you couldn't
tell if it was an implicit exit from the trap even that wasn't
particularly useful.

This will apply inside the next zshexit hooks, too.  It already applies
to traps on return from functions---that's a separate piece of code.
(It's preserved if multiple functions/hooks run; this is already handled
by the context used for a trap or hook.)

Obviously the status is only available until the first statement within
the trap/hook has run.

Index: Doc/Zsh/builtins.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/builtins.yo,v
retrieving revision 1.87
diff -u -r1.87 builtins.yo
--- Doc/Zsh/builtins.yo	20 Sep 2006 09:22:34 -0000	1.87
+++ Doc/Zsh/builtins.yo	10 Nov 2006 09:37:12 -0000
@@ -1252,6 +1252,8 @@
 If var(sig) is tt(0) or tt(EXIT)
 and the tt(trap) statement is executed inside the body of a function,
 then the command var(arg) is executed after the function completes.
+The value of tt($?) at the start of execution is the exit status of the
+shell or the return status of the function exiting.
 If var(sig) is tt(0) or tt(EXIT)
 and the tt(trap) statement is not executed inside the body of a function,
 then the command var(arg) is executed when the shell terminates.
Index: Doc/Zsh/func.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/func.yo,v
retrieving revision 1.14
diff -u -r1.14 func.yo
--- Doc/Zsh/func.yo	9 Nov 2006 11:04:11 -0000	1.14
+++ Doc/Zsh/func.yo	10 Nov 2006 09:37:12 -0000
@@ -248,6 +248,8 @@
 item(tt(TRAPEXIT))(
 Executed when the shell exits,
 or when the current function exits if defined inside a function.
+The value of tt($?) at the start of execution is the exit status of the
+shell or the return status of the function exiting.
 )
 findex(TRAPZERR)
 findex(TRAPERR)
Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.168
diff -u -r1.168 builtin.c
--- Src/builtin.c	9 Nov 2006 11:04:11 -0000	1.168
+++ Src/builtin.c	10 Nov 2006 09:37:14 -0000
@@ -4434,6 +4434,7 @@
 #endif
 	}
     }
+    lastval = val;
     if (sigtrapped[SIGEXIT])
 	dotrap(SIGEXIT);
     callhookfunc("zshexit", NULL, 1);


-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php


             reply	other threads:[~2006-11-10  9:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-10  9:40 Peter Stephenson [this message]
2006-11-10 15:58 ` Bart Schaefer
2006-11-10 16:09   ` Peter Stephenson
2006-11-11  5:28     ` Bart Schaefer
2006-11-11 13:13       ` Peter Stephenson

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=200611100940.kAA9ewZY012583@news01.csr.com \
    --to=pws@csr.com \
    --cc=zsh-workers@sunsite.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).