From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6387 invoked from network); 8 Sep 2001 06:50:37 -0000 Received: from sunsite.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 8 Sep 2001 06:50:37 -0000 Received: (qmail 23253 invoked by alias); 8 Sep 2001 06:50:30 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 15756 Received: (qmail 23242 invoked from network); 8 Sep 2001 06:50:28 -0000 From: Bart Schaefer Message-Id: <1010908065025.ZM18493@candle.brasslantern.com> Date: Sat, 8 Sep 2001 06:50:25 +0000 X-Mailer: Z-Mail (5.0.0 30July97) To: zsh-workers@sunsite.dk Subject: Value of $? after signal MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii The manual says under the "return" builtin: If return was executed from a trap in a TRAPNAL function, the effect is different for zero and non-zero return status. With zero status (or after an implicit return at the end of the trap), the shell will return to whatever it was previously processing; with a non-zero status, the shell will behave as interrupted except that the return status of the trap is retained. Note that the numeric value of the signal which caused the trap is passed as the first argument, so the statement `return $((128+$1))' will return the same status as if the signal had not been trapped. This is the only reference I can find to "exit status == 128 plus signal" in the zsh manual, but the bash2 manual says in the "simple command" grammar: The return value of a simple command is its exit status, or 128+n if the command is terminated by signal n. Both zsh and bash appear to do this, i.e. if you interrupt "sleep 10" with a ^C (SIGINT), $? is set to 130 in both shells. The odd bit is what happens when a command is stopped with ^Z (SIGSTOP) or with any other stop-signal (STOP, TTOU, etc.). In this case bash sets $? to 0, but zsh sets it to the signal number -- not 128+n, but n. So, e.g., if you ^Z mutt, which catches TSTP and then sends itself STOP, you get $? set to 19; but if you ^Z any command that doesn't catch TSTP, you get $? set to 20. I guess the reasoning in zsh is to not add 128 if the command has not been terminated, but still report the signal number? Or was the intent to use 128+n and we simply forgot the 128 somewhere? Does anybody remember how we arrived at this behavior? -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net