Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: dangerous behavior of while in zsh 5.6 ?
- X-seq: zsh-users 23696
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: dangerous behavior of while in zsh 5.6 ?
- Date: Wed, 3 Oct 2018 08:28:29 -0700
- Cc: Marc Chantreux <eiro@xxxxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=dk2LKTyljkS3xPRiu6/ZKdHZj7LdSMP0rnXidNJuv4o=; b=DWaFfvDGL73wFM97qwjoxW5+eBZpuqi2zroYvnNecN9BSxfRD1BoroyMlH8+7prgdF tlk6mxFywf8QbbVxMCxXaIe7r/UE98VLEVZGBRE7nXpFf3rckKkFa1BPug9L//citzap TBo5yft+tOMl/jozPvVKhTHGAindkw301Tklwy6VqUibJGtfMWBbaKcRvTMVp2F1VNo+ zCQIweHd3A7LVq/OJthNgZy6D/G+0kTt1J+RF/ocDEJOONwAd/8awpBTYTOGx5hfcza6 wwWlQBkivtx3cvO0GHpECImzs+Qv3gm1dCj3i9tPBl2BvefnQD/9xOrKj1geCwqsVdzx eCWQ==
- In-reply-to: <20181003143800.GA9162@prometheus.u-strasbg.fr>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <20181003143800.GA9162@prometheus.u-strasbg.fr>
On Wed, Oct 3, 2018 at 7:47 AM Marc Chantreux <eiro@xxxxxxxxx> wrote:
>
> a end of line after a condition is interpreted as an empty
> true block so:
>
> while (( i-- ))
> print $i
This is just a syntax error for me (or prints the PS2 prompt if
interactive), so I'm not sure how you're getting it to do anything.
This would certainly not be something new or different in 5.6.2.
In shell syntax, a newline is the same as a semicolon, so what you've
written should be the same as:
while (( i-- )); print $i
To make that a complete loop statement you have to follow it with "do
... done" or something in braces or parens.
> should mean:
>
> while (( i-- )) {print $i}
No, it should mean
while { (( i-- )); print $i; }
which will be an infiinte loop (if you ever supply the "do" block,
otherwise it's just a syntax error) because the exit status of the
loop condition { ... } will be that of the print statement, which is
never false.
> so it doesn't behave like the other loops:
>
> repeat 5 print $[i++]
> while (( i-- )) print $i
It's actually "repeat" that doesn't behave the same here, because
"repeat" has no test condition to follow the number of repetitions.
Thus
repeat 5 ; print $[i++]
is
repeat 5 { ; print $[i++]; }
Conversely the test condition for "while" is defined to be the whole
sequence of commands up to the keyword "do" or (with shortloops) one
of "{" or "(" or "((". Commands in that sequence may be separated &&
or || or | or semicolon or newline. This is not a bug, it's the way
the syntax is designed to work.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author