zsh-users
 help / color / mirror / code / Atom feed
* Filtering array on index
@ 2018-10-25 11:29 Jesper Nygårds
  2018-10-25 18:17 ` Mikael Magnusson
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Jesper Nygårds @ 2018-10-25 11:29 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 909 bytes --]

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?

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2019-09-08  9:00 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-25 11:29 Filtering array on index Jesper Nygårds
2018-10-25 18:17 ` Mikael Magnusson
2018-10-25 18:55   ` Jesper Nygårds
2018-10-25 19:42   ` Daniel Shahaf
2018-10-25 20:21 ` Bart Schaefer
2018-10-25 20:42   ` dana
2018-10-26  4:14     ` Jesper Nygårds
2018-10-26  7:59       ` Jesper Nygårds
2018-10-26  8:21         ` dana
2018-10-26  9:28           ` Jesper Nygårds
2018-10-28  2:45           ` Bart Schaefer
2019-07-23  3:38 ` Sebastian Gniazdowski
2019-07-23  7:42   ` Sebastian Gniazdowski
2019-07-23  8:03     ` Sebastian Gniazdowski
2019-09-08  8:59     ` Sebastian Gniazdowski

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).