From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 15134 invoked from network); 5 Jun 2020 20:42:34 -0000 Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTPUTF8; 5 Jun 2020 20:42:34 -0000 Received: (qmail 29981 invoked by alias); 5 Jun 2020 20:42:25 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 45989 Received: (qmail 26685 invoked by uid 1010); 5 Jun 2020 20:42:25 -0000 X-Qmail-Scanner-Diagnostics: from injection.crustytoothpaste.net by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.3/25828. spamassassin: 3.4.4. Clear:RC:0(192.241.140.119):SA:0(-2.0/5.0):. Processed in 2.191169 secs); 05 Jun 2020 20:42:25 -0000 X-Envelope-From: sandals@crustytoothpaste.net X-Qmail-Scanner-Mime-Attachments: |signature.asc| X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at crustytoothpaste.net designates 192.241.140.119 as permitted sender) Date: Fri, 5 Jun 2020 20:41:44 +0000 From: "brian m. carlson" To: Mikael Magnusson Cc: zsh-workers@zsh.org Subject: Re: [PATCH v2] exec: run final pipeline command in a subshell in sh mode Message-ID: <20200605204144.GD6569@camp.crustytoothpaste.net> References: <20200605015338.1347787-1-sandals@crustytoothpaste.net> <20200605015338.1347787-2-sandals@crustytoothpaste.net> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="hxkXGo8AKqTJ+9QI" Content-Disposition: inline In-Reply-To: X-Machine: Running on camp using GNU/Linux on x86_64 (Linux kernel 5.6.0-2-amd64) --hxkXGo8AKqTJ+9QI Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2020-06-05 at 10:21:41, Mikael Magnusson wrote: > On 6/5/20, brian m. carlson 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. >=20 > 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 =E2=80=9Cshall define an environment in whi= ch an application can be run with the behavior specified by POSIX.1-2017.=E2=80=9D 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. --=20 brian m. carlson: Houston, Texas, US OpenPGP: https://keybase.io/bk2204 --hxkXGo8AKqTJ+9QI Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.2.20 (GNU/Linux) iHUEABYKAB0WIQQILOaKnbxl+4PRw5F8DEliiIeigQUCXtquCAAKCRB8DEliiIei ga7UAQDF65JEsGFQ5Nwqmujzaed+gLVoH7CyXRIya/DvlnQqKwEAxad5z16MATVT E5dlYxflx8UM6gfJqsOL+igjijeQaQo= =/Gsg -----END PGP SIGNATURE----- --hxkXGo8AKqTJ+9QI--