[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: break exit status
From: |
Dan Douglas |
Subject: |
Re: break exit status |
Date: |
Sun, 06 Jul 2014 10:04:17 -0500 |
User-agent: |
KMail/4.13.2 (Linux/3.15.0-pf3+; KDE/4.13.2; x86_64; ; ) |
On Sunday, July 06, 2014 09:08:00 AM gregrwm wrote:
> if break would preserve the exit status of the preceding command then the
> above loop would have a useful exit status.
Completely agree.
> an option analogous to pipefail could request the better break behaviour
Needless to say, POSIX requires the current behavior:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_15_14
There is a slight inconsistency in a few shells when "! break" is used. See
the 2nd-to-last example here:
http://wiki.bash-hackers.org/dict/terms/exit_status?redirect=1#portability
The easiest workaround is to replace inner loops with function calls, because
"return" doesn't suffer from that problem. However that does make breaking out
of multiple levels cumbersome.
Frustratingly I'm pretty sure there isn't even a possible hackish eval or
alias workaround. Notice calling break from a function with a RETURN trap set
bypasses the trap if break results in jumping out of the function (Yes, I
tried that one long ago).
--
Dan Douglas