Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: `return` does not behave properly under `!`
- X-seq: zsh-workers 51110
- From: Stephane Chazelas <stephane@xxxxxxxxxxxx>
- To: Michael Greenberg <michael@greenberg.science>
- Cc: zsh-workers@xxxxxxx
- Subject: Re: `return` does not behave properly under `!`
- Date: Wed, 7 Dec 2022 08:42:55 +0000
- Archived-at: <https://zsh.org/workers/51110>
- In-reply-to: <m2a640qtt8.fsf@greenberg.science>
- List-id: <zsh-workers.zsh.org>
- Mail-followup-to: Michael Greenberg <michael@greenberg.science>, zsh-workers@xxxxxxx
- References: <m2a640qtt8.fsf@greenberg.science>
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