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

Filtering array on index



I have an array which is the result of using zparseopts on a specification
that makes it possible to specify several filters with a -v flag. The
resulting array might look like the following:

myarr=(-v filter1 -v filter2)

I want to get rid of the "-v" elements, but only when they are the flag,
and not the argument. In other words, I would the like the array (-v
filter1 -v -v) to result in (filter1 -v).

I had previously used:

${myarr:#-v}}

which worked well, as I could accept the fact that -v was not possible to
use as the option argument.

However, now I need to make sure that a -v argument is preserved, and I
thus need a compact way of specifying that I want to keep every other
element in the array.

The most compact way I have found is:
for dash arg in $myarr; do myarr[(r)$dash]=()

This works, but I was wondering if there's some more elegant solution,
preferrably without using iteration?


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