Thanks for giving me a heads up here. I have updated the bashdb
documentation for the skip command make clear that $? is no changed in
skipping an instruction.

More generally bash saves and restores some state on entry and exit to
extdebug, like the variable $? (the extdebug function can issue a command
which inside sets $? but on return $? I think is restored)

However there is other global state that isn't saved and restored. I think
this includes the set flags. I'm not sure that what gets saved and restored
is fully documented, but it probably should be.

On Fri, Apr 7, 2017 at 9:06 PM, Chet Ramey <chet.ra...@case.edu> wrote:

> On 4/4/17 5:08 PM, nesro wrote:
>
> >
> > To have both commands similar, let's assume the while as this:
> >
> > while (( 1 > 2 )); do :; done
> >
> > Thanks for explaining me why it happen, but now I don't know why for
> cycle
> > works and while does not.
> When extdebug is enabled, the command is skipped if the DEBUG trap returns
> non-zero.  This doesn't change $? (traps never do) and it doesn't cause the
> command that would have been run to return a non-zero exit status.  If it
> did, the combination of DEBUG and `set -e' would exit the shell, for
> example, and I'm sure it would not behave as the bash debugger would
> expect.  For that matter, why should a command that's not run fail?
>
> Since that command returns successfully, when it's used as the `while'
> command test, it causes the while command to execute forever.
>
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
>                  ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, UTech, CWRU    c...@case.edu    http://cnswww.cns.cwru.edu/~
> chet/
>

Reply via email to