From: Michael Greenberg <michael@greenberg.science>
To: zsh-workers@zsh.org
Subject: `return` does not behave properly under `!`
Date: Tue, 06 Dec 2022 13:18:59 -0500 [thread overview]
Message-ID: <m2a640qtt8.fsf@greenberg.science> (raw)
Following up an example from Harald van Dijk on the dash mailing list, I
discovered that zsh does not `return` properly under a `!`. Here are
four example programs:
```
f() {
while return 5
do
echo fail while1
break
done
}
f
echo $?
g() {
while ! return 6
do
echo fail while2
break
done
}
g
echo $?
h() {
while return 7 && return 8
do
echo fail while3
break
done
}
h
echo $?
i() {
! return 9
echo fail not
}
i
echo $?
```
I would expect the output:
```
5
6
7
9
```
But zsh produces:
```
5
0
7
0
```
The dash shell has a similar bug (no link, since the mailing list
archives aren't up yet), as does yash
<https://osdn.net/projects/yash/ticket/46224>.
Cheers,
Michael
next reply other threads:[~2022-12-06 18:19 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-06 18:18 Michael Greenberg [this message]
2022-12-07 4:53 ` Bart Schaefer
2022-12-07 8:42 ` Stephane Chazelas
2022-12-07 15:05 ` Michael Greenberg
2022-12-07 16:01 ` Stephane Chazelas
2022-12-07 16:16 ` Peter Stephenson
2022-12-07 17:06 ` Bart Schaefer
2022-12-07 17:21 ` Peter Stephenson
2022-12-07 18:51 ` Bart Schaefer
2022-12-07 17:10 ` Michael Greenberg
2022-12-09 15:22 ` Michael Greenberg
2022-12-09 16:21 ` Bart Schaefer
2022-12-09 19:20 ` Michael Greenberg
2022-12-07 16:08 ` Bart Schaefer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2a640qtt8.fsf@greenberg.science \
--to=michael@greenberg.science \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).