Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Filtering array on index
- X-seq: zsh-users 23718
- From: Jesper Nygårds <jesper.nygards@xxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Filtering array on index
- Date: Thu, 25 Oct 2018 13:29:01 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=Qfk8DU7G/m1zKRglQ423byy51lSqhFns1wLcV5VltRA=; b=uj1xXEzyrFKKpsHCiXD1ksWhbA/HgTIvqamtE+PNsFpTGTY/Voxm0n79No1XhrkgB8 R9QUsh5pIFoq0MfrY/XuAe7WhfpMoLyF/0kxWLMs3Svw76qXRSdOxDuGEFdbJHULQrDE x4ezbMeRL3aEDBOiwlHVgOYuznj27czrqkA5W6QGiqK7ae0E3jUty9oNFD7TIWycCgq5 aXmt5ZFduFqxdIaJzzuJUuiq0CI9otlTHay6NOuqfKkQhrKzBE4b+OSIIGU+Y7ARimFQ b6LtRLZbCVYcmQ2L2Plb2yTFOirrSKlJdLnLAAXcu6yt2m1rikhYLkB2rF2qGwvMDJUt OY/Q==
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
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