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

Re: selecting elements in array



On Apr 21,  4:06pm, Eric Mangold wrote:
} Subject: Re: selecting elements in array
}
} On Thu, 21 Apr 2005 13:43:55 +1000, Wataru Kagawa  
} <wkagawa@xxxxxxxxxxxxxxxxxxxx> wrote:
} 
} > How do I select elements with indices that are multiples of 3, in an  
} > array?  [...] for compadd.  Help is much appreciated.
} 
} for i in {1..3}; do
} print $list[$(($i*3))]
} done

Right, except replace "print" with "compadd", and you don't need the
$(( )) because the stuff in the [ ] is already treated as arithmetic.

    for i in {1..3}; do compadd $list[i*3]; done
or
    for ((i=3; $+list[i]; i+=3)); do compadd $list[i]; done

or any of a number of other ways.  There's not, however, a way to write
a single subscript parameter expansion that picks out non-contiguous
array slices.



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