zsh-workers
 help / color / mirror / code / Atom feed
* `return` does not behave properly under `!`
@ 2022-12-06 18:18 Michael Greenberg
  2022-12-07  4:53 ` Bart Schaefer
  2022-12-07  8:42 ` Stephane Chazelas
  0 siblings, 2 replies; 14+ messages in thread
From: Michael Greenberg @ 2022-12-06 18:18 UTC (permalink / raw)
  To: zsh-workers

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


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2022-12-09 19:21 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-06 18:18 `return` does not behave properly under `!` Michael Greenberg
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

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).