This is probably the strangest bug (or maybe pair of bugs) I've run into
in nearly five years of breaking shells by developing modernish.
I've traced it to an interaction between bash >= 4.2 (i.e.: bash with
shopt -s lastpipe) and variants of the Almquist shell, at least: dash,
gwsh, Busybox ash, FreeBSD sh, and NetBSD 9.0rc2 sh.
Symptom: if 'return' is invoked on bash in the last element of a pipe
executed in the main shell environment, then if you subsequently 'exec'
an Almquist shell variant so that it has the same PID, its 'wait'
builtin breaks.
I can consistently reproduce this on Linux, macOS, FreeBSD, NetBSD
9.0rc2, OpenBSD, and Solaris.
To reproduce this, you need bash >= 4.2, some Almquist shell variant,
and these two test scripts:
---begin test.bash---
fn() {
: | return
}
shopt -s lastpipe || exit
fn
exec "${1:-dash}" test.ash
---end test.bash---
---begin test.ash---
echo '*ash-begin'
: &
echo '*ash-middle'
wait "$!"
echo '*ash-end'
---end test.ash---
When executing test.bash with dash, gwsh, Busybox ash, or FreeBSD sh,
then test.ash simply waits forever on executing 'wait "$!"'.