Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: case $? fails



Roderick Schertler wrote:
> Running this script
>
>     #!/bin/zsh -f
>
>     print "version $ZSH_VERSION"
>
>     false
>     case $? in
>       0)  print "case says \$? is 0";;
>     esac
>
>     false
>     print "\$? was actually $?"
>
> gives me this buggy result
>
>     version 3.0.3-test4
>     case says $? is 0
>     $? was actually 1

while has the same problem unfortunately.  Similarily
for ((i=$?;;)) do echo $i; break; done
prints zero.  The patch below fixes these.  The for syntax is new in
zsh-3.1 so the first two hunks should be removed if the patch is applied
against zsh-3.0.3-test4.  Note that the case bug was not present in
zsh-3.0.2 but the while bug was there.

Zoltan


*** Src/loop.c  1997/02/11 14:23:47     3.1.2.0
--- Src/loop.c  1997/02/27 21:26:13
***************
*** 41,47 ****
      int val;
      LinkList args;

-     lastval = 0;
      node = cmd->u.forcmd;
      args = cmd->args;
      if (node->condition) {
--- 41,46 ----
***************
*** 58,63 ****
--- 57,63 ----
        for (x = pparams; *x; x++)
            addlinknode(args, ztrdup(*x));
      }
+     lastval = 0;
      loops++;
      pushheap();
      for (;;) {
***************
*** 267,277 ****

      olderrexit = noerrexit;
      node = cmd->u.whilecmd;
!     lastval = 0;
      pushheap();
      loops++;
      for (;;) {
-       oldval = lastval;
        list = (List) dupstruct(node->cont);
        noerrexit = 1;
        execlist(list, 1, 0);
--- 267,276 ----

      olderrexit = noerrexit;
      node = cmd->u.whilecmd;
!     oldval = 0;
      pushheap();
      loops++;
      for (;;) {
        list = (List) dupstruct(node->cont);
        noerrexit = 1;
        execlist(list, 1, 0);
***************
*** 295,300 ****
--- 294,300 ----
            lastval = 1;
            break;
        }
+       oldval = lastval;
      }
      popheap();
      loops--;
***************
*** 381,390 ****
      l = node->lists;
      p = node->pats;

-     lastval = 0;
      word = *p++;
      singsub(&word);
      untokenize(word);

      if (node) {
        while (*p) {
--- 381,390 ----
      l = node->lists;
      p = node->pats;

      word = *p++;
      singsub(&word);
      untokenize(word);
+     lastval = 0;

      if (node) {
        while (*p) {



Messages sorted by: Reverse Date, Date, Thread, Author