#1108081 dash: The exit status of "return" in the first list of the while/until loop

Package:
dash
Source:
dash
Description:
POSIX-compliant shell
Submitter:
Takaaki Konno
Date:
2025-06-20 08:41:04 UTC
Severity:
normal
#1108081#5
Date:
2025-06-20 08:29:25 UTC
From:
To:
Dear Maintainer,

POSIX.1-2024 describes the exit status of the return utility as follows:

https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/utilities/V3_chap02.html#return

    SYNOPSIS

    return [n]

    EXIT STATUS

    ... If n is not specified, the result shall be as if n were specified with
    the current value of the special parameter '?' ...

In most case, the return command works as expected in dash. For example:

    $ f() { false; return; }
    $ f; echo "$?"
    1

but in the first list of the while/until loop, it does not work as expected.
For example:

    f_while() {
        while false; return; do
            echo 'this line is never executed'
        done
    }

    f_until() {
        until false; return; do
            echo 'this line is never executed'
        done
    }

    f_while; echo "$?"
    f_until; echo "$?"

gives:

    0
    0

As the behavior of a POSIX-compliant shell, I expect "return" to return the
exit status of the preceding command even in this case. Is the above actual
behavior in dash intentional?

Kind regards,
Takaaki