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

Filtering an array



I am scratching my head over getting something seemingly simple to work.

I have written this function:

findfiles() {
    local myfiles myarg
    myfiles=( **/*$1* )
    shift
    for myarg in $@; do
        myfiles=${(M)myfiles:#*$myarg*}
    done
    print $myfiles
}

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, as exemplified by the following
session:


% ls
a  ab  abc  ac  b  bc  c
% findfiles a b
ab abc
% findfiles a b c
ab abc
% findfiles a c
abc ac
% findfiles a c b
abc ac

I would expect both "findfiles a b c" and "findfiles a c b" to only
return "abc", but for some reason the third argument to the function
is not considered.

Can anyone help me sort this out?



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