zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH v3 0/1] Run pipeline command in subshell in sh mode
@ 2021-01-04  0:22 brian m. carlson
  2021-01-04  0:22 ` [PATCH v3 1/1] exec: run final pipeline command in a " brian m. carlson
  0 siblings, 1 reply; 7+ messages in thread
From: brian m. carlson @ 2021-01-04  0:22 UTC (permalink / raw)
  To: zsh-workers

Most sh implementations[0] 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
this time.

v2 can be seen in the archives at
https://www.zsh.org/mla/workers/2020/msg00794.html.

I'm not subscribed to the list, so please CC me if you have questions or
comments.

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.

[0] 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
    well.

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(-)



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-04-10 23:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-04  0:22 [PATCH v3 0/1] Run pipeline command in subshell in sh mode brian m. carlson
2021-01-04  0:22 ` [PATCH v3 1/1] exec: run final pipeline command in a " brian m. carlson
2021-03-27 19:34   ` Lawrence Velázquez
2021-04-03 15:49     ` Lawrence Velázquez
2021-04-10 20:05       ` Lawrence Velázquez
2021-04-10 23:02   ` dana
2021-04-10 23:59     ` brian m. carlson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).