#945425 zsh: should run all pipeline elements in subshell in sh mode

Package:
zsh
Source:
zsh
Description:
shell with lots of features
Submitter:
"brian m. carlson"
Date:
2019-11-25 04:03:03 UTC
Severity:
normal
#945425#5
Date:
2019-11-24 17:02:22 UTC
From:
To:
POSIX mandates that all elements in a pipeline are run in subshells, but
permits extensions that run some or all of those elements in the main
shell environment instead.

zsh always runs the final element in a pipeline in the normal shell
environment, which breaks programs which expect to conform to POSIX.
For example, the Git testsuite fails in a variety of ways when zsh is
/bin/sh.

This behavior is fine as zsh, since in that case it's obvious that
extensions are being enabled, but when "emulate sh" is set, the final
element in a pipeline should also be run in a subshell for maximum
compatibility with POSIX.

As an example, the attached program should print "boo", "baz", and
"foo", in that order when run under "zsh --emulate sh", but does not:
----
% dash foo.sh
boo
baz
foo
% zsh --emulate sh foo.sh
boo
baz
baz
----