Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: selecting elements in array
- X-seq: zsh-users 8726
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: selecting elements in array
- Date: Thu, 21 Apr 2005 07:34:15 +0000
- In-reply-to: <op.spki9xi66k1y1x@aspen>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <1830d300995f75ea6076d5d38133c886@xxxxxxxxxxxxxxxxxxxx> <op.spki9xi66k1y1x@aspen>
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