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

`return` does not behave properly under `!`



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




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