zsh-workers
 help / color / mirror / code / Atom feed
From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: Mikael Magnusson <mikachu@gmail.com>
Cc: zsh-workers@zsh.org
Subject: Re: [PATCH v2] exec: run final pipeline command in a subshell in sh mode
Date: Fri, 5 Jun 2020 20:41:44 +0000	[thread overview]
Message-ID: <20200605204144.GD6569@camp.crustytoothpaste.net> (raw)
In-Reply-To: <CAHYJk3QwvTf28FGg4EFD9in7mGSHeHMCAcd_KtXnos6U3VrOdw@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2606 bytes --]

On 2020-06-05 at 10:21:41, Mikael Magnusson wrote:
> On 6/5/20, brian m. carlson <sandals@crustytoothpaste.net> wrote:
> > zsh typically runs the final command in a pipeline in the main shell
> > instead of a subshell.  However, POSIX requires that all commands in a
> > pipeline run in a subshell, but permits zsh's behavior as an extension.
> 
> What POSIX actually says is:
> "each command of a multi-command pipeline is in a subshell
> environment; as an extension, however, any or all commands in a
> pipeline may be executed in the current environment"
> Ie, it does not say "shall", so it doesn't require a subshell all, in
> fact it explicitly does permit not using one as you also say. The
> patch is possibly useful (seems unlikely to me), but to say it is
> required by POSIX is not true. If someone depends on every command in
> a pipeline being a subshell, they should fix their code, for example
> by adding ( ) around it (the command(s) or the whole pipeline).

POSIX makes a declarative statement about the behavior of a pipeline.
It is true that it doesn't explicitly use the word "shall" in this case,
since such a statement would explicitly prohibit the inclusion of an
extension at all and make it explicitly non-conforming.

What POSIX does say is that one “shall define an environment in which an
application can be run with the behavior specified by POSIX.1-2017.”
I'm proposing that "zsh --emulate sh" implement the POSIX behavior for
that reason.

I will tell you that as a practical matter, nobody writing code for sh
expects the last command not to be run in a subshell and consequently
lots of code is practically broken in this case with zsh as /bin/sh.
The Git Project is very fastidious about writing portable shell, as is
Debian, and I can tell you from experience that both are broken with zsh
as sh with the current behavior, even if they should not have made that
assumption.

zsh is a very popular interactive shell, and allowing it to be used as a
portable sh on systems where the system sh is less capable would be
really beneficial.  I would also like to see macOS users who decide to
use zsh as /bin/sh have a good experience with existing code that
overwhelmingly does make this assumption.

If your objection is to the wording, I'm happy to revise it to remove
the word "requires", but I do think this provides a lot of benefits for
the sh scripting case while not impacting users who are expecting
different behavior for the zsh case.
-- 
brian m. carlson: Houston, Texas, US
OpenPGP: https://keybase.io/bk2204

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 263 bytes --]

  reply	other threads:[~2020-06-05 20:42 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-05  1:53 [PATCH v2 0/1] Run pipeline command in " brian m. carlson
2020-06-05  1:53 ` [PATCH v2] exec: run final pipeline command in a " brian m. carlson
2020-06-05 10:21   ` Mikael Magnusson
2020-06-05 20:41     ` brian m. carlson [this message]
2020-06-06  4:33       ` [PATCH v2] exec: run final pipeline command in a subshell in sh modeZZ Daniel Shahaf
2020-06-06 16:28         ` brian m. carlson
2020-06-07 11:29           ` Daniel Shahaf
2020-06-07 16:55       ` [PATCH v2] exec: run final pipeline command in a subshell in sh mode Bart Schaefer
2020-06-07 17:24         ` Peter Stephenson
2020-06-09  7:57           ` Daniel Shahaf
2020-06-09 10:54             ` Mikael Magnusson
2020-06-17 18:26               ` Daniel Shahaf
2020-07-03 20:16                 ` brian m. carlson
2020-06-11  0:24         ` brian m. carlson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200605204144.GD6569@camp.crustytoothpaste.net \
    --to=sandals@crustytoothpaste.net \
    --cc=mikachu@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).