From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 0591b0cf for ; Sat, 24 Aug 2019 20:17:36 +0000 (UTC) Received: (qmail 16184 invoked by alias); 24 Aug 2019 20:17:28 -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: 44705 Received: (qmail 1736 invoked by uid 1010); 24 Aug 2019 20:17:28 -0000 X-Qmail-Scanner-Diagnostics: from kahlil.inlv.org by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.101.2/25545. spamassassin: 3.4.2. Clear:RC:0(37.59.109.123):SA:0(-1.9/5.0):. Processed in 2.972724 secs); 24 Aug 2019 20:17:28 -0000 X-Envelope-From: martijn@inlv.org X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at inlv.org does not designate permitted sender hosts) From: Martijn Dekker Subject: RFC: &&/|| vs. & operator precedence To: Zsh hackers list Message-ID: Date: Sat, 24 Aug 2019 22:16:44 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 8bit Sorry if this has been discussed before -- it's hard to search for '&' in the archives. On all other shells, true && false || foo & launches 'true && false || foo' as a background job. On zsh (including sh mode), only 'foo' is the background job. IOW, the '&' operator on other POSIX shells takes an entire AND-OR (&&/||) list as the background job, whereas on zsh, only the last command is taken as the background job. POSIX says in 2.9.3: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_03 | A list is a sequence of one or more AND-OR lists separated by the | operators ';' and '&'. but later on in 2.9.3.1: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_03_02 | If a command is terminated by the control operator ( '&' | ), the shell shall execute the command asynchronously in a subshell. So that is quite ambiguous. The first suggests that '&' should act like most POSIX shells do, the second suggests it should act like zsh does. This ambiguity is basically the subject of an Austin Group bug opened by Stéphane Chazelas: http://austingroupbugs.net/view.php?id=1254 He is proposing that POSIX should prescribe the behaviour of the majority, which would make zsh non-compliant as of the next POSIX edition. An alternative might be to make this unspecified instead, so that both zsh and other shells are compliant as is, and cross-platform scripters would be expected to use explicit braces where necessary (as they already have to do now). So, in anticipation of this being resolved one way or another in POSIX, it might be worth discussing what (if anything) should change in zsh. I think the opinion of the zsh maintainers matters here. Would it be feasible to make zsh act like other POSIX shells in sh emulation mode only? I could imagine that being difficult as this touches on shell grammar, not builtins. If not, would it be acceptable to change the precedence of these operators to match other POSIX shells in zsh as a whole? How many old zsh scripts could that break? - Martijn -- modernish -- harness the shell https://github.com/modernish/modernish