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 30949 invoked from network); 3 Mar 2021 01:02:10 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 3 Mar 2021 01:02:10 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1614733330; b=iC4hTbKGrUS3Xjuxmfm6eEFjZRkSakP6VavKbiBFwumHBoH6kdKb6vlSetRwd6iaYETuFCrBn9 YzKYjVFcPXhnZuzvF5q/EH+raQ2bcq9alEjg1/HO/NU8g+G9GX4MGUOfDhuRcEBK/peLilUzLc 5Y1uGH079lu4r13h+tLJYgsft3QJ+VxhjLOMMoDfpKiJsaGdebIaW+0/bZQ0FhRPl6wzFBdYGw 86E1PGJghTWaHsrICuYwB/9zudOJZ+zb4xEgEXdUz7rwUk29BHaKdDLJkzoW9lECVOYCe3crCq n3mzmu5TjgLPUC2DEw2uHFX8SW6p9mbS//rozQKxWh47tg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (out3-smtp.messagingengine.com) smtp.remote-ip=66.111.4.27; dkim=pass header.d=daniel.shahaf.name header.s=fm2 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm2 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1614733330; bh=VIFaCnE7Qb3pcQ6+KuYdfoiFpXQRojzVnxW9JUHH1gA=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Message-ID:Subject:To:From:Date:DKIM-Signature: DKIM-Signature:DKIM-Signature; b=eMqQJMu6l3clO0n8oUZAnlT5WqE6gCSBc0eOjpioInN0FssQFYGjMRLJ2r0xitHr2UUUr5cE1l gE6qeYJFpFQIlGxS1mJbyAOiup8Z8miTqX5K5MRqIybw26cJubZYNhw+aG+vJrxx6JHueLCN7+ KRWHv3EhpxbMVJINugOuY31cFmDEzFXzOf5esvQ0SWgqUU1sjMhrTE1+uAyqhoAFSJAS1yj75n iXKOjNTLB/3pP+HBEivQGU3+kDmdGWkOi9mFA9+9sdlBx1lmBWk3uyFIsYQu/5o4+QLRNZdK5Q KiOboZbKAJ+5/SjAg50CniFUaSaveq6u3wuVMvBhf/a4vw==; 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:In-Reply-To:Content-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:To:From:Date: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=+71ncwQ++lpBqcqivQ62aMghTgzotzggImw1NouqgwU=; b=Ckr+XBx0NJJssYmDeRTR1xD/LP sh9y0BuQ3dUj2TlLOpw109EkzkqyQ1e6j0DmstB/KxLRV2ED2OdXJd+iiO5Cd5vSF04R/9EN0kQgA Xi+RXJXgE+muzq/tm1PJ9i9fgPGuHe8nwazxM872ArzTPr2nXbSEDKmHlo+ZZTxYoOc7dGQ67giOK Yd9waYM+e+dHr8d0HUBI2fW0V/A/97UBfHZ7TlvdZI7NP6/Pu07ofROLM8FIZoGbvkFVsPS0Uiifn TomrchCYmn6VIyNtl46j4FtKWk1rvdvL8oq5RNpxtPrgoOU7quWfDhtgCscRUKbhn8uhONWcTjDpg kjytHErA==; Received: from authenticated user by zero.zsh.org with local id 1lHFtv-000PL9-Q4; Wed, 03 Mar 2021 01:02:07 +0000 Authentication-Results: zsh.org; iprev=pass (out3-smtp.messagingengine.com) smtp.remote-ip=66.111.4.27; dkim=pass header.d=daniel.shahaf.name header.s=fm2 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm2 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none Received: from out3-smtp.messagingengine.com ([66.111.4.27]:50705) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1lHFtZ-000PBY-JZ; Wed, 03 Mar 2021 01:01:46 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id E87EC5C00A4; Tue, 2 Mar 2021 20:01:43 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 02 Mar 2021 20:01:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=date:from:to:subject:message-id:references :mime-version:content-type:content-transfer-encoding :in-reply-to; s=fm2; bh=+71ncwQ++lpBqcqivQ62aMghTgzotzggImw1Nouq gwU=; b=CMJ5ZqSswGbZRnlBQasLrcbrslnKZyyc0Mr/wpCq3TqUZSCyqY8MODua kYKiYLc8p5HTAlgHpuTqxC+eOkFE+m1xJ8FPz4loGjW14UQOgKXk5k3AesD/Uswl s97FTgsiKmLmn9uMn5WEvPh1zXexW9Q1nCvxDdNgjz62lBr6myOxWK9XHFQEIFgC WDqqlkdb91dc850u4uz1nrPbgoOQYiqB7v0DITbymryo10plf/Lpcxxk4g5WUjG4 2kT3sgW8t75aalgQBbOnMRL5l9Xnlm1WEI6GFfjIKtAjMnnqUyXNbnzoaofSjoQl 33cQZM5ikhbSsLWQEKNuEteowjIWqQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=+71ncwQ++lpBqcqivQ62aMghTgzotzggImw1Nouqg wU=; b=gNPLC3cbJ0+G+wHqg57rr9NtbkiNLpUiAuyPEMdbaqfd5VmHeXtbB2NTM juLyjEL9+o4URoX5Itvdee6zRBh9TvRk4MbJECnFC9MjXqrSmHJd6pRtjdbIBXpt yVOdNCnRTVZrS35zgnQOEOuxpV+RmieDSM3PszdQmeqjNN5tin6zStdxqRuGrFai h+GeflXHxR0MDtLLB6w35zcs3t9y9YFlKEQp4ggl8BruY0kbPaA55E3r6q394NPa qAilT0XjHwLT/PSpwB+hc0+K9gMvwEzdgt9BIG5RbocUWUEpvlloge7Y2K0+xKwj 5LB01cwln9cg1Bf4s+xpVV5/jdJog== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledruddtuddgvdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggugfgjfgesmh ektdertderjeenucfhrhhomhepffgrnhhivghlucfuhhgrhhgrfhcuoegurdhssegurghn ihgvlhdrshhhrghhrghfrdhnrghmvgeqnecuggftrfgrthhtvghrnhepudehgedvieetie fhjeevueejudekkefgkeeltedvleethefgudduieevveevleffnecuffhomhgrihhnpehg ihhthhhusgdrtghomhenucfkphepjeelrddujeelrdehledruddvtdenucevlhhushhtvg hrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegurdhssegurghnihgvlhdr shhhrghhrghfrdhnrghmvg X-ME-Proxy: Received: from tarpaulin.shahaf.local2 (bzq-79-179-59-120.red.bezeqint.net [79.179.59.120]) by mail.messagingengine.com (Postfix) with ESMTPA id 3E42D1080068 for ; Tue, 2 Mar 2021 20:01:43 -0500 (EST) Received: by tarpaulin.shahaf.local2 (Postfix, from userid 1005) id 4DqwgS2f9SzRq; Wed, 3 Mar 2021 01:01:40 +0000 (UTC) Date: Wed, 3 Mar 2021 01:01:40 +0000 From: Daniel Shahaf To: zsh-workers@zsh.org Subject: [PATCH] FAQ 3.31 revision (lack of bash/zsh interchangeability) (was: Re: disown -a) Message-ID: <20210303010140.GB3219@tarpaulin.shahaf.local2> References: <28c28f42-632d-4ebc-857e-64022f59a895@www.fastmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="YZ5djTAD1cGYuMQK" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <28c28f42-632d-4ebc-857e-64022f59a895@www.fastmail.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Seq: 48131 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: --YZ5djTAD1cGYuMQK Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit Daniel Shahaf wrote on Wed, Mar 03, 2021 at 00:05:38 +0000: > [...] https://github.com/zsh-users/zsh/blob/5ede2c55f144593c16498c3131a76e188114a9c6/Etc/FAQ.yo#L2056-L2102, > the first and penultimate paragraphs. ⋮ > zsh is not a bug-for-bug reimplementation of bash. This prompted me to revisit that FAQ entry. Patch series attached. I'm also attaching the resulting FAQ text with the series applied. Notable is that 0003 is an interim state that compiles, in the sense that «make -C Etc» passes, but shouldn't be built and released. The log message explains why. (It also features an xkcd reference.) Feedback welcome. Cheers, Daniel [[[ sect(Why does my bash script report an error when I run it under zsh?) label(331) em(tl;dr:) bash is not the reference implementation of zsh, and zsh is not a bug-for-bug compatible reimplementation of bash. bash and zsh are different programming languages. They are not interchangeable; programs written for either of these languages will, in general, not run under the other. (The situation is similar with many other pairs of closely-related languages, such as Python 2 and Python 3; C and C++; and even C89 and C11.) When bash and zsh behave differently on the same input, whether zsh's behaviour is a bug does not depend on what bash does on the same input; rather, it depends on what zsh's user manual specifies. (By way of comparison, it's not a bug in Emacs that mytt(:q!) doesn't cause it to exit.) That being said, the bash and zsh languages do have a common subset, and it is feasible to write non-trivial pieces of code that would run under either of them, if one is sufficiently familiar with both of them. However, a difference between bash's behaviour and zsh's does not imply that zsh has a bug. The difference might be a bug in zsh, a bug in bash, or a bug in neither shell (see link(3.1)(31) for an example). The recommended way to deal with these differences depends on what kind of piece of code is in question: a myem(script) or a myem(plugin). For em(scripts) emdash() external commands that are located in tt($PATH), or located elsewhere and are executed by giving their path explicitly (as in mytt(ls), mytt(/etc/rc.d/sshd), and mytt(./configure)) emdash() the answer is simple: Don't run bash scripts under zsh. If the scripts were written for bash, run them in bash. There's absolutely no problem with having mytt(#!/usr/bin/env bash) scripts even if mytt(zsh) is your shell for interactive sessions. In fact, if you've recently changed to zsh, we myem(recommend) that you keep your scripts as mytt(#!/usr/bin/env bash), at least for a while: this would make the change more gradual and flatten your learning curve. Once you're used to zsh, you can decide for each script whether to port it to zsh or keep it as-is. For myem(plugins) emdash() pieces of code executed within the shell itself, loaded via the mytt(.), mytt(source), or mytt(autoload) builtins, added to mytt(.zshrc), or pasted interactively at the shell prompt emdash() one may consider it worthwhile to invest the effort to make them runnable under either shell. However, as mentioned above, doing so requires one to be familiar with both shells, and either steer clear of their differences or handle them explicitly with conditional code (such as mytt(if test -n "$ZSH_VERSION")). In summary, if you'd like to run a bash script or plugin under zsh, you must port the script or plugin properly, reviewing it line by line for differences between the two languages and adjusting it accordingly, just like you would when translating a book from American English to British English. ]]] --YZ5djTAD1cGYuMQK Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0001-FAQ-3.31-Add-a-one-sentence-summary.patch.txt" >From d4bbcc7708e2ef29225fc6191d3b3672277be68d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 3 Mar 2021 00:17:53 +0000 Subject: [PATCH 1/4] FAQ: 3.31: Add a one-sentence summary --- Etc/FAQ.yo | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Etc/FAQ.yo b/Etc/FAQ.yo index 7aeddd89c..9831b027c 100644 --- a/Etc/FAQ.yo +++ b/Etc/FAQ.yo @@ -2056,6 +2056,9 @@ sect(Why doesn't the expansion mytt(*.{tex,aux,pdf}) do what I expect?) sect(Why does my bash script report an error when I run it under zsh?) label(331) + em(tl;dr:) bash is not the reference implementation of zsh, and zsh is not + a bug-for-bug compatible reimplementation of bash. + bash and zsh are different programming languages. They are not interchangeable; programs written for either of these languages will, in general, not run under the other. (The situation is similar with --YZ5djTAD1cGYuMQK Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0002-FAQ-3.31-Tweak-summary-paragraph.patch.txt" >From cd0575d297b473a3acb1dc0f8c6408435d45b956 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 3 Mar 2021 00:18:18 +0000 Subject: [PATCH 2/4] FAQ: 3.31: Tweak summary paragraph --- Etc/FAQ.yo | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Etc/FAQ.yo b/Etc/FAQ.yo index 9831b027c..f0a50489c 100644 --- a/Etc/FAQ.yo +++ b/Etc/FAQ.yo @@ -2099,9 +2099,10 @@ label(331) (By way of comparison, it's not a bug in Emacs that mytt(:q!) doesn't cause it to exit.) - If you'd like to run a bash script under zsh, you must port the script + In summary, + if you'd like to run a bash script or plugin under zsh, you must port the script or plugin properly, reviewing it line by line for differences between the two - languages and adjusting the script accordingly, just like you would + languages and adjusting it accordingly, just like you would when translating a book from American English to British English. --YZ5djTAD1cGYuMQK Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0003-FAQ-3.31-Move-two-paragraphs-unchanged-reorderin.patch.txt" >From b06b24dac90e02df9a72a234ce882b7e29c0c1ff Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 3 Mar 2021 00:18:24 +0000 Subject: [PATCH 3/4] FAQ: 3.31: Move two paragraphs unchanged, reordering them Factored out from the next patch for readability of the diff. The answer, as it stands in this commit, doesn't flow correctly. In order to keep the diffs small and easy to follow, this commit simply adds a TODO to record this issue, a TODO which is fixed by the next commit in this series (the child of this commit). Thus, a request: DEAR PEOPLE FROM THE FUTURE: Please don't create new branches off this commit; create them off the parent commit or off the child commit instead. Thank you. --- Etc/FAQ.yo | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/Etc/FAQ.yo b/Etc/FAQ.yo index f0a50489c..e444c0b77 100644 --- a/Etc/FAQ.yo +++ b/Etc/FAQ.yo @@ -2065,6 +2065,22 @@ label(331) many other pairs of closely-related languages, such as Python 2 and Python 3; C and C++; and even C89 and C11.) + When bash and zsh behave differently on the same input, whether zsh's + behaviour is a bug does not depend on what bash does on the same + input; rather, it depends on what zsh's user manual specifies. + (By way of comparison, it's not a bug in Emacs that mytt(:q!) doesn't + cause it to exit.) + + Since the bash and zsh languages do have a common subset, it is + feasible to write non-trivial plugins that would run under either of + them, if one is sufficiently familiar with both of them. However, + a difference between bash's behaviour and zsh's does not imply that + zsh has a bug. It myem(might) be a bug in zsh, but it might also be + a bug in bash, or simply a difference that isn't a bug in either shell + (see link(3.1)(31) for an example). + + COMMENT(TODO: Move here the paragraph about "That's the answer for..." and reverse it) + So, don't run bash scripts under zsh. If the scripts were written for bash, run them in bash. There's absolutely no problem with having mytt(#!/usr/bin/env bash) scripts even if mytt(zsh) is your shell for @@ -2076,6 +2092,7 @@ label(331) learning curve. Once you're used to zsh, you can decide for each script whether to port it to zsh or keep it as-is. + COMMENT(TODO: That's the paragraph the comment above refers to) That's the answer for myem(scripts), i.e., for external commands that are located in tt($PATH), or located elsewhere and are executed by giving their path explicitly (as in mytt(ls), mytt(/etc/rc.d/sshd), @@ -2085,20 +2102,6 @@ label(331) pasted interactively at the shell prompt emdash() the answer is different. - Since the bash and zsh languages do have a common subset, it is - feasible to write non-trivial plugins that would run under either of - them, if one is sufficiently familiar with both of them. However, - a difference between bash's behaviour and zsh's does not imply that - zsh has a bug. It myem(might) be a bug in zsh, but it might also be - a bug in bash, or simply a difference that isn't a bug in either shell - (see link(3.1)(31) for an example). - - When bash and zsh behave differently on the same input, whether zsh's - behaviour is a bug does not depend on what bash does on the same - input; rather, it depends on what zsh's user manual specifies. - (By way of comparison, it's not a bug in Emacs that mytt(:q!) doesn't - cause it to exit.) - In summary, if you'd like to run a bash script or plugin under zsh, you must port the script or plugin properly, reviewing it line by line for differences between the two --YZ5djTAD1cGYuMQK Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0004-FAQ-3.31-Rearrange.patch.txt" >From 75500491625f69faaab45f5b3775720acfecdbbe Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 3 Mar 2021 00:34:11 +0000 Subject: [PATCH 4/4] FAQ: 3.31: Rearrange --- Etc/FAQ.yo | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/Etc/FAQ.yo b/Etc/FAQ.yo index e444c0b77..d899b61c4 100644 --- a/Etc/FAQ.yo +++ b/Etc/FAQ.yo @@ -2071,17 +2071,23 @@ label(331) (By way of comparison, it's not a bug in Emacs that mytt(:q!) doesn't cause it to exit.) - Since the bash and zsh languages do have a common subset, it is - feasible to write non-trivial plugins that would run under either of + That being said, the bash and zsh languages do have a common subset, and it is + feasible to write non-trivial pieces of code that would run under either of them, if one is sufficiently familiar with both of them. However, a difference between bash's behaviour and zsh's does not imply that - zsh has a bug. It myem(might) be a bug in zsh, but it might also be - a bug in bash, or simply a difference that isn't a bug in either shell + zsh has a bug. The difference might be a bug in zsh, a bug in bash, or + a bug in neither shell (see link(3.1)(31) for an example). - COMMENT(TODO: Move here the paragraph about "That's the answer for..." and reverse it) + The recommended way to deal with these differences depends on what kind + of piece of code is in question: a myem(script) or a myem(plugin). + + For em(scripts) emdash() external commands that + are located in tt($PATH), or located elsewhere and are executed by + giving their path explicitly (as in mytt(ls), mytt(/etc/rc.d/sshd), + and mytt(./configure)) emdash() the answer is simple: - So, don't run bash scripts under zsh. If the scripts were written for + Don't run bash scripts under zsh. If the scripts were written for bash, run them in bash. There's absolutely no problem with having mytt(#!/usr/bin/env bash) scripts even if mytt(zsh) is your shell for interactive sessions. @@ -2092,15 +2098,14 @@ label(331) learning curve. Once you're used to zsh, you can decide for each script whether to port it to zsh or keep it as-is. - COMMENT(TODO: That's the paragraph the comment above refers to) - That's the answer for myem(scripts), i.e., for external commands that - are located in tt($PATH), or located elsewhere and are executed by - giving their path explicitly (as in mytt(ls), mytt(/etc/rc.d/sshd), - and mytt(./configure)). For myem(plugins) emdash() code that is - executed within the shell itself, that's loaded via the mytt(.), + For myem(plugins) emdash() pieces of code + executed within the shell itself, loaded via the mytt(.), mytt(source), or mytt(autoload) builtins, added to mytt(.zshrc), or - pasted interactively at the shell prompt emdash() the answer is - different. + pasted interactively at the shell prompt emdash() one may consider it + worthwhile to invest the effort to make them runnable under either shell. + However, as mentioned above, doing so requires one to be familiar with both + shells, and either steer clear of their differences or handle them explicitly + with conditional code (such as mytt(if test -n "$ZSH_VERSION")). In summary, if you'd like to run a bash script or plugin under zsh, you must port the script or plugin --YZ5djTAD1cGYuMQK--