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.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 31124 invoked from network); 16 May 2021 16:43:45 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 16 May 2021 16:43:45 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1621183426; b=eLGbTn0qXjG9hpUZylqjII5FrI6NXFd3MLpAt4JqGY5bvn0BNWQ+3/T4SxjT9XUXrVcimNB9qh l9r8j2G0wJOGM5xfJpXwGkfEoHgcL6GjrAVDTk058me/bAikwlaYZMezmGw4ubar51Exd6o1hI fRQ3LvCuu/pHrjCnr6lKxEYNHFMK6PGEj/6GqReqWUPnUvkw/B3JLUl3ZxhfPpn7FAcMmhxaED RXwWDnIqb07rUeXMASNfBfe4aVPDYzvlTRs/k47y12eWc7kj49MFEzsZIs0kll7bSONM3y7f9Z 4nErYXJpFlAw5o1WSwFqzIVXR3ApltiQI7Ych0Pxz5SkAg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (relay4-d.mail.gandi.net) smtp.remote-ip=217.70.183.196; dmarc=none header.from=chazelas.org; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1621183426; bh=j2jJaVjUyfJ750mkdeXhsP/hjPqTbslHDOQNqGOLfus=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:DKIM-Signature; b=GmBSXCO7cIQMj3eicAvzAt9G4vQvsOMPWaVLcQUQmfRgdXYhCuH7barecFu/ZyLoWXSd1Eh0xm K8sqfxF/2FYkqeCTRHdcyzRBnN4M3Y01BpoqH0EJ4w6KPrdX/KSz7sv9Fg3DknyAMHisiZx0JD BR3qj4B/bFzSk/MTckcqEu3yUdJMWFa2J8Qz/2bLf5yUZDFKUL/pY5jNHYIzstq0n4XAa3y2LA ctgqKzBpyfEEVzeuyxJ7vLIOuhqldG87MUAuu49d/m34lQxPQr+K2rHJNQPW3wTlUOrJ/Aewjm 0idwt2dAAmjKUzNdv2cdaQVvdW/LlohlttRMG/w+pXMwLg==; 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-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=tBUMbq/2CnjHegKJztvViOiBG4sTrAbJVI/fR/e9GS8=; b=CpMlJSKG6gH65w8lF9KkfqgxqB wPgZ1b6e+9e0bbPRXxbbl8ZleAGG+hFAhf51xmod/yg86ls7g2vOvpLzguW7mwXmljkfTaUUY5/UG dWfnVsxKD7Sn/MpQkXW48bqBMn5wgNO9IfaQKRKbA1sch0Trj0vqa2TUj+96XB9eGBFmBCl44Zwtl QgtwrpipHh+wyHvZL7SAA3NgqyMNugLrjQNdO5qK+nhVz9dw0RfJV7Jzu13UIKiFqToR79/hn9Esz lt8++V8dvtqdjcFsyZDZsJpabwmh8eGGpqaBepr1Lck+RxWFUwe/dFeSaMCqywwVlFdNsAnzhu6dP dcilOADg==; Received: from authenticated user by zero.zsh.org with local id 1liJrl-0001bx-Hs; Sun, 16 May 2021 16:43:45 +0000 Authentication-Results: zsh.org; iprev=pass (relay4-d.mail.gandi.net) smtp.remote-ip=217.70.183.196; dmarc=none header.from=chazelas.org; arc=none Received: from relay4-d.mail.gandi.net ([217.70.183.196]:38565) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1liJrW-0001Kb-HV; Sun, 16 May 2021 16:43:31 +0000 Received: (Authenticated sender: stephane@chazelas.org) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 8A4D1E0005; Sun, 16 May 2021 16:43:28 +0000 (UTC) Date: Sun, 16 May 2021 17:43:28 +0100 From: Stephane Chazelas To: Arseny Maslennikov Cc: zsh-workers@zsh.org Subject: Re: 'while do done' hangs interactive zsh Message-ID: <20210516164328.x7jnh3gfqfiidd7a@chazelas.org> Mail-Followup-To: Arseny Maslennikov , zsh-workers@zsh.org References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Seq: 48845 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: 2021-05-16 12:16:24 +0300, Arseny Maslennikov: > Hi everyone! > > When zsh tries to execute "while do; done", it enters a busy loop: > > % dash -c 'while do; done' > dash: 1: Syntax error: "do" unexpected > % bash -c 'while do; done' > bash: -c: line 1: syntax error near unexpected token `do' > bash: -c: line 1: `while do; done' > % zsh -c 'while do; done' # never finishes/prompts by itself > ^C > zsh -c 'while do; done' 27,73s user 0,00s system 99% cpu 27,732 total 4k maxrss > > Even more, if the user enters "while do; done" in an interactive zsh > instance, the busy loop is not interruptible by ^C, ^\ or ^Z; the shell > has to be killed via some external means. > > To be fair, I have discovered the bug with the semicolon omitted ("while do done"). [...] As far as I can tell, it works as documented. while LIST do LIST done LIST is not explicitely specified, but it does appear to be a list of 0 or more pipelines. Or in other words any script. So: while do done Runs the empty list of pipelines as long as the empty list of pipelines is successful. You'll see you can also do if then echo the empty list is successful; fi repeat 1000000 do done myfunc() { } if [ -e x ]; then else echo does not exist; fi That does not even make zsh non-POSIX compliant, as those are not valid POSIX sh syntax, so implementations are free to do whatever they want. If you want your *script* to be portable, you should not write: while do echo yes; done as a forever loop, as other shells require at least one pipeline in the condition LIST (which to me just looks like an arbitrary, unecessary limitation), but that does not mean shell implementations have to return an error here. -- Stephane