Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: For loop bug



"Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx> writes:

> On Sep 13,  5:58pm, Philippe Troin wrote:
> } Subject: Re: For loop bug
> }
> } Peter Stephenson <pws@xxxxxxxxxxxxxxxxxxxxxxxx> writes:
> } 
> } Does it fix this one as well?
> } 
> }   % for i in 1 2 3; do { {echo $i; [[ $i == 2 ]] && exit 1; } || break }; \
> }   > done && echo X
> }   1
> }   X
> }   % 
> 
> That is not a bug.
> 
> zagzig% [[ x == y ]] && true
> zagzig% echo $?
> 1
> 
> Hence { [[ $i == 2 ]] && exit 1; } is false, and { false || break } means
> break.  The && expression is only true if -both- branches are true.

Agreed.

> 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.

But shouldn't it print:

  1
  2
  X

???

The echo $i with i set to 2 occurs before the exit and break
statements.

Phil.



Messages sorted by: Reverse Date, Date, Thread, Author