commit:     51d23a2686196ff7562b7b506124097674fcd2ac
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Tue Oct 14 06:17:02 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Tue Oct 14 12:59:09 2025 +0000
URL:        
https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=51d23a26

Refrain from negating the break builtin

Presently, there are two instances in which "! break" is used to break a
loop, with the expectation that the resulting status be non-zero. That
is, given that the exit status of break is 0, the act of negating it is
supposed to produce a status of 1. Unfortunately, the various sh(1)
implementations cannot be relied upon to behave in this manner.

$ bash -c 'for x in 1; do ! break; done; echo "$?"'
1
$ dash -c 'for x in 1; do ! break; done; echo "$?"'
0

Address this issue by using return instead.

Link: https://www.mail-archive.com/austin-group-l <AT> 
opengroup.org/msg12302.html
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 functions.sh              | 6 +++---
 functions/experimental.sh | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/functions.sh b/functions.sh
index cff6f5a..771a7bc 100644
--- a/functions.sh
+++ b/functions.sh
@@ -1068,8 +1068,8 @@ fi
 for _ in "${genfun_basedir}/functions"/*.sh; do
        if ! test -e "$_"; then
                warn "no gentoo-functions modules were found (genfun_basedir 
might be set incorrectly)"
-               ! break
+               false
        elif _want_module "$_"; then
-               . "$_" || return
-       fi
+               . "$_"
+       fi || return
 done

diff --git a/functions/experimental.sh b/functions/experimental.sh
index 7c2fb25..d3e2e3a 100644
--- a/functions/experimental.sh
+++ b/functions/experimental.sh
@@ -172,7 +172,7 @@ str_between()
                printf '%s\n' "$@" |
                sort |
                while IFS= read -r line; do
-                       eval "[ \"\${line}\" = \"\$$(( i += 1 ))\" ]" || ! break
+                       eval "[ \"\${line}\" = \"\$$(( i += 1 ))\" ]" || return
                done
        fi
 }

Reply via email to