zsh-users
 help / color / mirror / code / Atom feed
* Filtering an array
@ 2012-02-24  7:11 Jesper Nygårds
  2012-02-24 10:25 ` Felix Herrmann
  2012-02-28  7:24 ` S. Cowles
  0 siblings, 2 replies; 4+ messages in thread
From: Jesper Nygårds @ 2012-02-24  7:11 UTC (permalink / raw)
  To: zsh-users

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?


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

end of thread, other threads:[~2012-02-29 14:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-24  7:11 Filtering an array Jesper Nygårds
2012-02-24 10:25 ` Felix Herrmann
2012-02-28  7:24 ` S. Cowles
2012-02-29 13:43   ` Jesper Nygårds

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).