Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Filtering an array
- X-seq: zsh-users 16784
- From: Felix Herrmann <fhml@xxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: Filtering an array
- Date: Fri, 24 Feb 2012 11:25:11 +0100 (CET)
- In-reply-to: <CABZhJg9QFx89rSrRhaN8UPNpbfsKHGQbAVJhzYGT+05PYeRR=g@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CABZhJg9QFx89rSrRhaN8UPNpbfsKHGQbAVJhzYGT+05PYeRR=g@mail.gmail.com>
Hi :)
On Fri, 24 Feb 2012 08:11:29 +0100, Jesper Nygårds wrote:
> The idea is to find all files that contain all of the strings given. I
> first find all files containing the first argument, then shift away
> the first argument and filter the array of file names with each of the
> remaining arguments.
>
> However, for some reason only the first round of filtering (i.e. using
> the second argument) is happening[...].
I'm no expert at all at zsh-scripts but I think the problem is that
myfiles isn't an array anymore after the first iteration. I changed your
code to the following:
findfiles() {
local myfiles myarg
myfiles=( **/*$1* )
shift
for myarg; do
myfiles=(${(M)myfiles:#*$myarg*})
done
print $myfiles
}
There are two little differences here. First of all, I didn't write '$@'
in the for-line. If you don't give an 'in x', for iterates over the
remaining arguments.
The second difference - and the more important one - is, that I put ()
around the rhs of the myfiles-assignment, to make sure to assign an
array to the variable myfiles. I think that was the catch. After this
modification, your script works fine :)
Greetings,
Felix Herrmann.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author