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=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 26319 invoked from network); 4 Jan 2021 00:23:15 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 4 Jan 2021 00:23:15 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1609719795; b=wRann6GY4nYr1ZzTP+VKkz/mtWH5oMspAbRHbshLnqU7hkpAfq4YekImTRELD35TnVNUBDngd4 /pXyDfGwOJRx8X9CYPhezbYTMxAqnrICOApMHTRDx6BhrekZMIKAzhco00yWy34dZ++cj67evl Fev1zRqqvOxOE6F1jMAgonn8A2dgsvL7Cnuw5dbLIlONGHjLRbpf1WVXtoTMihhh7lUNrVHL5x rn0WSfk5H6ldYML9kAbEBds/JSlOLYNHn40lzJDcl2Yn7kaAhd6xtK7G2DhOj8VQl2zg3U9jb7 rZfaVV5Hu39Fm42m65YH7QzJzRvVuGOmFQhvaQNv+lVWbA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (injection.crustytoothpaste.net) smtp.remote-ip=192.241.140.119; dkim=pass header.d=crustytoothpaste.net header.s=default header.a=rsa-sha256; dmarc=none header.from=crustytoothpaste.net; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1609719795; bh=rg0X/fTBYpM2zR+vE+km844YLENKaQKz3rSkFwG9M4M=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:MIME-Version: Message-ID:Date:Subject:To:From:DKIM-Signature:DKIM-Signature; b=YTvP7l0wm9hiceWYOTV1oxs5EJp8IbXynvzUHQckRU1s6myDs5OGWGGW4QfjAXkk4aSk9FoI/K 0NGUnIGeLo7OkHFwrDgAy4x8R1+EBPacwV+jP74HOxp7A4YVxCC05wgJfpvpZoz1pbLVN0d5kM AnrwzR6ZQJJYXgu5FyWvOEQHL7F1nGi1Irg5V03p7r4IImdfOZo2I6UR8EFqwpbbFVXShurdOQ /IaUdfm53K74NpUlIwR6e2QyGGngJGnPACxMhIOcFqdhRD0g9J3yqMTA/CZ9lD315pO0lr+XX8 PMoY6bHDOSz3vyD+ztkT/vJpATtjc/1PJq2yJubf4eQIgg==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Message-Id:Date:Subject:To:From:Reply-To:Cc: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References; bh=pe8V99zNbgsAxWYf0FLsiBpZHRR0puhgxCCpSSOq9nc=; b=KJ2xqBOfrATTJK8VPd06vrVxIm El1YaVnaY0POK9t41caNl60TBch3yKldsBIJajnjY0Yey9IDZ+N8r6oKdW9o7rT5mPnPVKmDb3b6S p7e5Xowq0dv3QT7V7yfSlhCQSVYCZ+8HpToehTBaCgie96ui/KUps9W0woz+6DmgemCzL+w14w526 5vMdIWeVYIkH4LiPE0HaGvCxK2R3c2nr4p9G+yK4k9gaGE5F9n29LlnTvYr8Hsv61+IsSLWnBYhtd Br4aOdWmWu7pZ6YpKx5ofrqZHwllEBJvFJ7qX4FqzgsB7IwBuIL856+aMnFI0Q7IF3c2WfBAi7sd4 yWGGp4TA==; Received: from authenticated user by zero.zsh.org with local id 1kwDeR-000OM9-Tx; Mon, 04 Jan 2021 00:23:12 +0000 Authentication-Results: zsh.org; iprev=pass (injection.crustytoothpaste.net) smtp.remote-ip=192.241.140.119; dkim=pass header.d=crustytoothpaste.net header.s=default header.a=rsa-sha256; dmarc=none header.from=crustytoothpaste.net; arc=none Received: from injection.crustytoothpaste.net ([192.241.140.119]:47966) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-CHACHA20-POLY1305:256) id 1kwDe9-000OCJ-O5; Mon, 04 Jan 2021 00:22:55 +0000 Received: from camp.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:b610:a2f0:36c1:12e3]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id 0D51260810 for ; Mon, 4 Jan 2021 00:22:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1609719772; bh=rg0X/fTBYpM2zR+vE+km844YLENKaQKz3rSkFwG9M4M=; h=From:To:Subject:Date:Content-Type:From:Reply-To:Subject:Date:To: CC:Resent-Date:Resent-From:Resent-To:Resent-Cc:In-Reply-To: References:Content-Type:Content-Disposition; b=XEZJ1QMrE1IPnozc2gm7OuKYn3PuLqYq3HBJpo/2OxXsE8ZSewg3CJZTnMlKunY8z cNcAVHcWg0e1Y08L9uDieeUpVxb/8X2JoeIJYz0LYphWwVNM67JLgKlVxOlBTRgb/o MLnGAAw1WEz7MFR57zJRsmFX/l3FfEZqSd7JlupEy2v+p+a0iHfOw0lrZQhVQU3UMw ygg2umTJ6CLh6lDY6xJxEHKO2o1C+PRrwTHg2F+b/1HEsfP9/r6itXfhn5hlnJlZnj jPWx5qB5E7CKYMF4Y5KN+UCvOTNxz8a+IvtXSBRQxV0IArmfpPbSuPujjnfc74OaiQ qbNVC6rImHSKhN6sb6nRMxnL04H6nrX08As+W2U3OHtbABXym9qq/xYyIpTjre+Zja 8W553smByIIr+UcLvdE0gF+pULCJfnmNY43SUGreKb5rhDz1GYvwpnbvZIRKNa6R+a X5S2l8Kz4woheNSQQQ3zITOTU7aET5dAKgzziQ+huZFlcx8fAj6 From: "brian m. carlson" To: zsh-workers@zsh.org Subject: [PATCH v3 0/1] Run pipeline command in subshell in sh mode Date: Mon, 4 Jan 2021 00:22:12 +0000 Message-Id: <20210104002213.2703305-1-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Seq: 47793 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Archived-At: 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(-)