Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: `return` does not behave properly under `!`



> On 07/12/2022 16:01 Stephane Chazelas <stephane@xxxxxxxxxxxx> wrote:
> I can't see why one would call ! return if not to expect that to
> have an effect on the exit status.

I agree with Michael's argument that shows that logically it
can't have an effect on the status, whatever you want.  The return
happens immediately, so the effect of any status within the function
is not taken into account.  It's not actually any more use adding a
! in front than using

return $?
(( ! $? ))

Even if the ! had an effect, it would just be on the effect of
falling off the end, which you've explicitly told it you don't want.
I suppose a more precise parallel would be

{
  true
  return $?
} always {
  return (( !$? ))
}

which returns 0 as the second return comes too late to affect
the return status.

pws




Messages sorted by: Reverse Date, Date, Thread, Author