On 13/02/2024 21:04, Thorsten Glaser via austin-group-l at The Open Group wrote:
Chet Ramey wrote, according to the list archive
ontinue' is a builtin; continue has a return status; !' says to
negate it. It seems easy to come to the conclusion that the script
should return 1.

Yes, I can see how people could come to the conclusion.

But “continue”, if it unwinds the loop, doesn’t really return,
so its return status does not pass to the ! construct but is
directly set before the next loop round or exit, in mksh (and
other pdsh-derived shells).

That's an implementation detail that is not part of the spec. The spec says that $? reports "the decimal exit status of the most recent pipeline". The most recent pipeline is "! continue". You're interpreting "! continue" as something like "continue; (exit $(( !$? )))" so that "continue" is a pipeline of its own, but that's neither how it's specified nor how other shells implement it.

You write:

> After all, the continue utility doesn't know it's called by the ! construct.

In ash-derived shells, this basically works because internally, the continue utility, like all utilities, does know it's called by the ! construct, because the call is wrapped in a function that checks if the result was negated. But there are other ways to make this work too.

Cheers,
Harald van Dijk

            • ... Oğuz via austin-group-l at The Open Group
              • ... Harald van Dijk via austin-group-l at The Open Group
              • ... Oğuz via austin-group-l at The Open Group
              • ... Robert Elz via austin-group-l at The Open Group
      • Re:... Chet Ramey via austin-group-l at The Open Group
        • ... Christoph Anton Mitterer via austin-group-l at The Open Group
          • ... Chet Ramey via austin-group-l at The Open Group
        • ... Robert Elz via austin-group-l at The Open Group
          • ... Vincent Lefevre via austin-group-l at The Open Group
  • Re: sh 'cont... Thorsten Glaser via austin-group-l at The Open Group
    • Re: sh ... Harald van Dijk via austin-group-l at The Open Group
      • Re:... Harald van Dijk via austin-group-l at The Open Group
        • ... Oğuz via austin-group-l at The Open Group

Reply via email to