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

Re: for loop question



On Tue, Nov 04, 2014 at 09:56:39AM +0800, Han Pingtian wrote:
> On Sun, Nov 02, 2014 at 09:37:13PM +0000, Stephane Chazelas wrote:
> > 2014-11-02 13:00:14 -0800, Bart Schaefer:
> > > > I've fiddled around with various modifications but it seems to dislike "
> > > [ -n "$TLC[i]" ] "
> > > > even though the 'while' loop is happy with it.  That expression evaluates
> > > to true or
> > > > false, does it not? So why won't 'for' swallow it?
> > > 
> > > The double parents (( )) are special arithmetic syntax.  You can't use an
> > > ordinary shell command like "test" ( for which "[" is an alias) inside that
> > > construct.
> > 
> > You could with:
> > 
> > for ((i=1; (z[$([ -n "$TLC[i]" ])0]),$? == 0; i++))
> >   print -ru2 -- $TLC[i]
> > 
> What does the (z[$([ -n "$TLC[i]" ])0]) mean, please?
> 
I think I have got the meaning of it. The goal is to run 
'[ -n "$TLC[i]" ]' in a math context, so embed the testing in the
subscript of 'z[..]'. The 'z' will be explained as a array in this math
context, the value of '$z[...]' is ignored, only the result of 
'[ -n "$TLC[i]" ]' is compared with 0.



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