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

Re: PATCH: skip command from debug trap



On Wed, Aug 6, 2008 at 1:54 PM, Peter Stephenson <pws@xxxxxxx> wrote:
> "Rocky Bernstein" wrote:
>> Others have noted the challenges in adding an option to return. Making
>> the semantics of the return statement already more complicated doesn't
>> seem wise.
>
> However, as I've pointed out I can guarantee to make that compatible
> with the current shell, and at the same time make return work as in
> other shells (apart from the math eval of the numeric argument, which
> would cause an error in other shells anyway) which it doesn't at the
> moment.  Once we have the latter adding an option is trivial.  Adding an
> option to a builtin is about the simplest thing it's possible to do.

Ok. Adding an option to the return builtin is simple, even if there is
no other shell that I know of that currently does this.

But given the choice of adding
   1) an option in the return statement everywhere that is specific to
just "trap DEBUG" or
   2) specifying what specific numbers do when on a return from "trap DEBUG",

isn't 2) simpler and more consistent with programming in shell
languages work? I take it as a given that every function or command is
going to have error codes that are somewhat arbitrary and that I'm not
going to intuit.

For example POSIX 1003.1 specifies that grep returns 1 when no lines
were selected and greater than 1 if there was an error, and for xargs
it says return code 126 means "The utility specified by *utility* was
found but could not be invoked. Seems a bit arbitrary and not
something I am likely to remember past my current need. But I think
someone working with shells is used to the idea that different
functions or commands return numbers indicate certain things.


>
>> A couple other approaches are setting a variable or calling a routine.
>>  For example  "trap_return --skip"  or TRAP_RETURN="skip"
>
> On the other hand, I can't make this compatible with existing versions
> (the standard namespace pollution problem).
>
> I don't like adding a new builtin just for this.
>
> The variable version is doable, we've done similar things before.  You'd
> have to note that it didn't force return from the current environment,
> either the inline trap or TRAPDEBUG.  You'd also have to be prepared for
> the shell to manipulate the variable behind your back, else you'd run
> into problems with having it set on future traps.  It's not disastrous,
> but I'm not convinced this is simpler.  In fact, at the moment it seems
> to me manifestly much more complicated.
>
> --
> 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