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

eval and resetting $? (Was Re: trap DEBUG + set -o DEBUG_BEFORE_CMD not setting $? nonzero in current CVS)



Thanks. This seems to work.

However when I use it I run into something else that looks like either
a bug or at least something whose behavior should be documented. In
the following program it feels like $? gets changed/reset? before eval
is run:

#!/usr/local/bin/zsh -f
cmd='print $?'
fdsafsdsfa # Invalid command
eval $cmd  # print $? works and so does
                  # ./file-containing: print $?

print $? works because $? is expanded before print is run. And
sourcing a file which contains the string I want to eval also works,
so this gives me a workaround for this problem.

But somehow I think that a string writing that to a file and sourcing
it should be equivalent to eval'ing the string.



On Mon, Aug 4, 2008 at 1:49 PM, Peter Stephenson <pws@xxxxxxx> wrote:
> On Mon, 4 Aug 2008 06:08:39 -0400
> "Rocky Bernstein" <rocky.bernstein@xxxxxxxxx> wrote:
>> The following code doesn't show $? as nonzero inside trap DEBUG using the
>> CVS source I just downloaded and built.
>>
>> However I don't get this problem on the Ubuntu zsh-beta or zsh.
>> Removing DEBUG_BEFORE_CMD (or I guess having debug run after the
>> command) does set/show $? properly.
>>
>> #!/tmp/zsh/Src/zsh -f
>> #!/src/external-cvs/zsh/Src/zsh -f
>> set -o DEBUG_BEFORE_CMD
>> trap 'print $?' DEBUG
>> fdasfsdafd  # invalid command
>> :
>
> Turns out to be unfinished business with the previous patch:  that code I
> patched needs also to be told when we're not in a trap at all.  It was
> triggering after the trap, resetting the status.
>
> I must write tests for both.
>
> Index: Src/init.c
> ===================================================================
> RCS file: /cvsroot/zsh/zsh/Src/init.c,v
> retrieving revision 1.89
> diff -u -r1.89 init.c
> --- Src/init.c  4 Aug 2008 17:32:20 -0000       1.89
> +++ Src/init.c  4 Aug 2008 17:46:26 -0000
> @@ -191,7 +191,7 @@
>            exit(lastval);
>        if (((!interact || sourcelevel) && errflag) || retflag)
>            break;
> -       if (trapreturn >= 0) {
> +       if (intrap && trapreturn >= 0) {
>            lastval = trapreturn;
>            trapreturn = 0;
>        }
>
>
> --
> Peter Stephenson <pws@xxxxxxx>                  Software Engineer
> CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
> Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070
>



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