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

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



2022-12-06 13:18:59 -0500, Michael Greenberg:
[...]
> i() {
>   ! return 9
>   echo fail not
> }
> i
> echo $?
> ```
[...]
> 0
[...]

That:

! return n

Behaves like return !n (and ! return behave like return !$? (or
return "$(( ! $? ))" in POSIX syntax) doesn't sound totally off
to me. As written, I would say the POSIX spec may even be
requiring it.

That's consistent with ! break causing the while/until loop it's
in returning with failure which I've seen code rely upon (AFAIK,
that's the only way to get those loops to return with failure;
doesn't work in pdksh and derivatives though).

-- 
Stephane




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