zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: 'case' zeroes "$?"
Date: Mon, 10 Oct 2016 09:55:22 +0100	[thread overview]
Message-ID: <20161010095522.5778c2fd@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <3493e3d3-e578-31d1-27de-06d8d0c35944@inlv.org>

On Sun, 9 Oct 2016 23:01:35 +0200
Martijn Dekker <martijn@inlv.org> wrote:
> Unlike on other shells, 'case' on zsh zeroes "$?" before executing a
> command within 'case', making it more inconvenient to test exit status.
> 
> Example:
> 
> (exit 37) || case $? in 37) echo "$?";; esac

This looks straightforward.  The first $? in the case pattern is expanded
as a command line argument, before the case is executed, so missed this.

diff --git a/Src/loop.c b/Src/loop.c
index 3b9d021..94b61b7 100644
--- a/Src/loop.c
+++ b/Src/loop.c
@@ -592,7 +592,6 @@ execcase(Estate state, int do_exec)
     word = ecgetstr(state, EC_DUP, NULL);
     singsub(&word);
     untokenize(word);
-    lastval = 0;
 
     cmdpush(CS_CASE);
     while (state->pc < end) {
diff --git a/Test/A01grammar.ztst b/Test/A01grammar.ztst
index 0b1085c..0e77f3e 100644
--- a/Test/A01grammar.ztst
+++ b/Test/A01grammar.ztst
@@ -757,6 +757,14 @@
 >}
 >Stuff here
 
+  (exit 37)
+  case $? in
+    (37) echo $?
+    ;;
+  esac
+0:case retains exit status for execution of cases
+>37
+
   x=1
   x=2 | echo $x
   echo $x


  parent reply	other threads:[~2016-10-10  8:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20161009210214eucas1p21d253eca777c6b4e9f6e243aa18da25e@eucas1p2.samsung.com>
2016-10-09 21:01 ` Martijn Dekker
2016-10-09 21:34   ` Martijn Dekker
2016-10-10  8:55   ` Peter Stephenson [this message]
2016-10-13  9:30     ` Martijn Dekker

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=20161010095522.5778c2fd@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.com \
    --cc=zsh-workers@zsh.org \
    /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).