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

Re: For loop bug



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.

Further, { } is not a subshell, so { [[ 2 == 2 ]] && exit 1; } would most
likely produce something like

login:

which might surprise you even more.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   



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