[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: while loop with extdebug + debug trap always returning 1

From: Chet Ramey
Subject: Re: while loop with extdebug + debug trap always returning 1
Date: Fri, 7 Apr 2017 21:06:14 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.0

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    address@hidden    http://cnswww.cns.cwru.edu/~chet/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]