From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: zsh-users-return-23696-ml=inbox.vuxu.org@zsh.org 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=DKIM_SIGNED,DKIM_VALID, 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 c530db25 for ; Wed, 3 Oct 2018 15:29:05 +0000 (UTC) Received: (qmail 15858 invoked by alias); 3 Oct 2018 15:28:52 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: X-Seq: 23696 Received: (qmail 322 invoked by uid 1010); 3 Oct 2018 15:28:51 -0000 X-Qmail-Scanner-Diagnostics: from mail-lj1-f181.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.208.181):SA:0(-1.9/5.0):. Processed in 3.963535 secs); 03 Oct 2018 15:28:51 -0000 X-Envelope-From: schaefer@brasslantern.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | 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== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=dk2LKTyljkS3xPRiu6/ZKdHZj7LdSMP0rnXidNJuv4o=; b=k1TMS6d0NemCA9AqeZzNZmdxRl9WKaSMWaf8aHzBc0JSWetXoH/wAlqy75nWkJOw2Y B+w7K+J06dvr/vuym466zliKKmF3gBFL4loqo6a7J9vnEwTTuNEz54+PEQ51ghk9Kdgd eVzNXr6QwYl6TDsBTC8tkLiMSZ0W1MadlLPU0bwHue4NcxtCgJXx1v6dLHEFYZOx4QG5 gKXbK+V6FkN8L2cXxh+RUkYZ3k9Cvhq1kbbrcjyVdIlTfuTc+IjjTUKx9Qt/mUcjpXOZ XE5Jrl9l4Ikf2zm42w0wlbiqHIOKVV28tayiCOu3yblxS8fopfrK4N2WhzFE8Vb6wr9K XDXA== X-Gm-Message-State: ABuFfog4A7/lA/TTLD7vIH3ZQ45Z3IgYueepHf0GyEfxKcO2EQN+9wjO C3jld3482ioHT2NamhE13ujzRGJlBQgyP9VJjBvNrYz6LfM= X-Google-Smtp-Source: ACcGV61+lauLax75WHrM8Ofrf3m9XxF/Ztw/PKeoxhYRTZ35TozrFYo/LiRrHk7u8242lReTqBpNmjxOSyFgFas8VVM= X-Received: by 2002:a2e:6353:: with SMTP id x80-v6mr1457543ljb.11.1538580522198; Wed, 03 Oct 2018 08:28:42 -0700 (PDT) MIME-Version: 1.0 References: <20181003143800.GA9162@prometheus.u-strasbg.fr> In-Reply-To: <20181003143800.GA9162@prometheus.u-strasbg.fr> From: Bart Schaefer Date: Wed, 3 Oct 2018 08:28:29 -0700 Message-ID: Subject: Re: dangerous behavior of while in zsh 5.6 ? To: Zsh Users Cc: Marc Chantreux Content-Type: text/plain; charset="UTF-8" On Wed, Oct 3, 2018 at 7:47 AM Marc Chantreux 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.