Zsh Mailing List Archive
Messages sorted by:
[PATCH v3 0/1] Run pipeline command in subshell in sh mode
- X-seq: zsh-workers 47793
- From: "brian m. carlson" <sandals@xxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: [PATCH v3 0/1] Run pipeline command in subshell in sh mode
- Date: Mon, 4 Jan 2021 00:22:12 +0000
- Archived-at: <https://zsh.org/workers/47793>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-workers/2021-01/20210104002213.2703305-1-sandals%40crustytoothpaste.net>
- List-id: <zsh-workers.zsh.org>
Most sh implementations run each command in a pipeline in a subshell,
although zsh (and AT&T ksh) do not: instead, they run the final command
in the main shell. This leads to very different behavior when the final
command is a shell function which modifies variables.
zsh is starting to be used in some cases as /bin/sh, such as on macOS
Catalina. Consequently, it makes sense to emulate the more common sh
behavior as much as possible when emulating sh, since that's the least
surprising behavior, and the behavior that many programs unwittingly
rely on. This patch does exactly that.
With this patch, using "zsh --emulate sh" passes the Git testsuite. I
expect that it will also be fully functional as /bin/sh on Debian,
although I have not tested.
There was some discussion about this change and it was agreed that it
was a good patch, but it needed a note in the incompatibilities section,
so I've added one. I'm happy to hear about additional changes people
would like to see; I hope that I'll get around to them a little faster
v2 can be seen in the archives at
I'm not subscribed to the list, so please CC me if you have questions or
Changes from v2:
* Update commit message to remove text about which there was
disagreement (what POSIX actually says about this issue).
* Add note in incompatibilities section.
Changes from v1:
* Expanded commit message to make the code easier to reason about.
 bash, dash, posh, pdksh, mksh, busybox sh, FreeBSD's /bin/sh (ash),
and OpenBSD's /bin/sh and ksh implementations. I believe, but am
not certain, that the original Bourne sh provided this behavior as
brian m. carlson (1):
exec: run final pipeline command in a subshell in sh mode
README | 4 ++++
Src/exec.c | 10 ++++++----
Test/B07emulate.ztst | 22 ++++++++++++++++++++++
3 files changed, 32 insertions(+), 4 deletions(-)
Messages sorted by: