From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20190 invoked from network); 27 Oct 2000 11:38:10 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 27 Oct 2000 11:38:10 -0000 Received: (qmail 18967 invoked by alias); 27 Oct 2000 11:37:52 -0000 Mailing-List: contact zsh-users-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 3482 Received: (qmail 18959 invoked from network); 27 Oct 2000 11:37:52 -0000 X-Envelope-Sender-Is: Andrej.Borsenkow@mow.siemens.ru (at relayer david.siemens.de) From: "Andrej Borsenkow" To: "Akim Demaille" , Subject: RE: Trap and exit Date: Fri, 27 Oct 2000 15:37:48 +0400 Message-ID: <000001c0400a$54f99fb0$21c9ca95@mow.siemens.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) Importance: Normal In-Reply-To: X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 > > 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