From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6383 invoked from network); 16 Sep 2002 18:27:03 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 16 Sep 2002 18:27:03 -0000 Received: (qmail 24369 invoked by alias); 16 Sep 2002 18:26:51 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 17683 Received: (qmail 24350 invoked from network); 16 Sep 2002 18:26:49 -0000 To: "Bart Schaefer" Cc: zsh-workers@sunsite.dk Subject: Re: For loop bug References: <20020913233156.324A31C0E9@pwstephenson.fsnet.co.uk> <871y7xs7yd.fsf@ceramic.fifi.org> <1020914045657.ZM12939@candle.brasslantern.com> <87elbufs3q.fsf@ceramic.fifi.org> <1020916062550.ZM29286@candle.brasslantern.com> From: Philippe Troin Date: 16 Sep 2002 11:26:45 -0700 In-Reply-To: <1020916062550.ZM29286@candle.brasslantern.com> Message-ID: <873cs9pz8a.fsf@ceramic.fifi.org> User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: Philippe Troin "Bart Schaefer" writes: > [Excerpts reordered for clarity.] > > On Sep 15, 9:58pm, Philippe Troin wrote: > } Subject: Re: For loop bug > } > } "Bart Schaefer" writes: > } > } > On Sep 13, 5:58pm, Philippe Troin wrote: > } > } > } > } % for i in 1 2 3; do { {echo $i; [[ $i == 2 ]] && exit 1; } || break }; > } > } > done && echo X > } > } 1 > } > } X > } > } % > } > > } > That is not a bug. > } > } But shouldn't it print: > } > } 1 > } 2 > } X > > No, it shouldn't. "for i in 1 2 3 ..." > > OK, so the first time around the loop i=1, and zsh echoes 1. > > Now we're testing [[ $i == 2 ]], which is [[ 1 == 2 ]] which is false; > hence we have { false && exit 1; } which doesn't call exit but also > doesn't evaluate as true, because the first branch of the && is false. > > So the outer expression becomes { { false } || break }; and the loop ends > immediately. > > } The echo $i with i set to 2 occurs before the exit and break > } statements. > > $i never has a chance to get set to 2. Got that part. Thanks for the clarifications. > } > Further, { } is not a subshell, so { [[ 2 == 2 ]] && exit 1; } would most > } > likely produce something like > } > > } > login: > } > > } > which might surprise you even more. > } > } I'm not sure I get this part. > > If you call { exit 1 } from an interactive zsh, the shell will exit and > you'll end up back at your login prompt (or your xterm will disappear or > your remote connection will drop or whatever). Expressions in { } are > evaluated in the current shell. If it were ( exit 1 ) with parens, that's > evaluated in a subshell and the interactive shell would keep running. Indeed. However my version of zsh does not exit: it goes on happily as if nothing happened. Phil.