On Wed, Feb 14, 2024 at 8:47 AM Harald van Dijk <a...@gigawatt.nl> wrote:
> POSIX specifies:
>
>  > The value of the special parameter '?' shall be set to n, an unsigned
> decimal integer, or to the exit status of the last command executed if n
> is not specified.
>
> In your example, n is 1, therefore $? shall be set to 1. Insofar as
> there is an exit status of the 'return' command itself, it is ignored
> because the 'return' command specifies that the usual rules for $?,
> those where it picks up the last pipeline's exit status, do not apply.
> As the negation only applies to the pipeline's exit status, that is
> ignored as well.
>
> ksh behaves the same way.
>
> Other shells do not, and return 0. I agree with you that 0 strikes me as
> a more logical result as well, but I cannot see an argument that POSIX
> permits so, I cannot see it permit any result other than 1.

Thanks. I was just asking to clarify, I don't have a preference for
either behavior yet.

Given the script in OP, gwsh and dash 0.5.12 also print 0 by the way,
but dash 0.5.11 prints 1. yash 2.54 and yash 2.55 also differ in the
same way. You think these recent changes result from a
misinterpretation of 202x draft?

  • sh 'continue... Thorsten Glaser via austin-group-l at The Open Group
    • Re: sh ... Chet Ramey via austin-group-l at The Open Group
      • Re:... 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
            • ... Harald van Dijk via austin-group-l at The Open Group
              • ... 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
        • ... 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

Reply via email to