On Wed, Jun 12, 2019 at 12:54 AM Richard Ulmer <maillists.rul...@mailbox.org> wrote:
> while making the Kakoune editor work on OpenBSD, I encountered some > strange behaviour [1]. This little script doesn't work with the OpenBSD > sh, but works at least with dash, bash and zsh: > > mkfifo 'testfifo' > cat "$( > ( printf 'foo\n' > testfifo 2>&1 ) > /dev/null 2>&1 & > printf 'testfifo' > )" > > I can make it work for all the mentioned shells like this: > > mkfifo 'testfifo' > cat "$( > ( ( printf 'foo\n' > testfifo 2>&1 ) & ) > /dev/null 2>&1 > printf 'testfifo' > )" > > Can someone explain or justify the behaviour of the OpenBSD sh, or do > you think this is a bug? > This is a bug, almost certainly from an over-zealous optimization in the logic handling subshells where the possibility that an inner redirection could be blocking wasn't taken into account when it tries to avoid unnecessary forks. Sorry, I don't have a fix in my back pocket. Your workaround is good; I'll note the intermediate set of parens can also be braces, which would let you avoid the otherwise necessary whitespace between open-parens if that grates on your soul like it does mine. :) Philip Guenther