zsh-users
 help / color / mirror / code / Atom feed
From: "Andrej Borsenkow" <Andrej.Borsenkow@mow.siemens.ru>
To: "Akim Demaille" <akim@epita.fr>, <zsh-users@sunsite.auc.dk>
Subject: RE: Trap and exit
Date: Fri, 27 Oct 2000 15:37:48 +0400	[thread overview]
Message-ID: <000001c0400a$54f99fb0$21c9ca95@mow.siemens.ru> (raw)
In-Reply-To: <mv4pukm8sx7.fsf@nostromo.lrde.epita.fr>

>
> I am not claiming this is a bug in Zsh, but I confess I prefer the
> behavior from Bash and Ash.
>
> /tmp % cat foo.sh
> nostromo 12:42
> #! /bin/sh
> trap 'echo trap: $?' 0
> exit 59
> /tmp % ash ./foo.sh
> nostromo 12:42
> trap: 59
> /tmp % bash ./foo.sh
> nostromo Err 59
> trap: 59
> /tmp % zsh ./foo.sh
> nostromo Err 59
> trap: 0
> /tmp %
> nostromo Err 59
>
> What do you think?
>

It looks like a bug in Zsh. Quoting Unix 98:

=============
The environment in which the shell executes a trap on EXIT will be identical
to the environment immediately after the last command executed before the trap
on EXIT was taken.
=============

In this case last command was 'exit 59'. What is exit code of _this_ command?
Quoting Unix 98 again:

=============
The exit status will be n, if specified. Otherwise, the value will be the exit
value of the last command executed, or zero if no command was executed. When
exit is executed in a trap action, the last command is considered to be the
command that executed immediately preceding the trap action.
=============

So, on entry into TRAPEXIT function $? is expected to be the same as exit
status. At least, it is how I understand two statements above.

cheers

-andrej


  reply	other threads:[~2000-10-27 11:38 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-10-27 10:44 Akim Demaille
2000-10-27 11:37 ` Andrej Borsenkow [this message]
2000-10-27 11:49   ` Andrej Borsenkow
2000-10-27 12:47     ` Akim Demaille
2000-10-27 13:05       ` Andrej Borsenkow
2000-10-27 12:46   ` Akim Demaille
2000-10-27 13:06     ` Andrej Borsenkow
2000-10-27 13:19   ` Peter Stephenson
2000-10-27 13:28     ` Akim Demaille
2000-10-27 13:39     ` Andrej Borsenkow
2000-10-27 15:26       ` Bart Schaefer

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='000001c0400a$54f99fb0$21c9ca95@mow.siemens.ru' \
    --to=andrej.borsenkow@mow.siemens.ru \
    --cc=akim@epita.fr \
    --cc=zsh-users@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).