From: "Jesper Nygårds" <jesper.nygards@gmail.com>
To: zsh-users@zsh.org
Subject: Filtering an array
Date: Fri, 24 Feb 2012 08:11:29 +0100 [thread overview]
Message-ID: <CABZhJg9QFx89rSrRhaN8UPNpbfsKHGQbAVJhzYGT+05PYeRR=g@mail.gmail.com> (raw)
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?
next reply other threads:[~2012-02-24 7:11 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-24 7:11 Jesper Nygårds [this message]
2012-02-24 10:25 ` Felix Herrmann
2012-02-28 7:24 ` S. Cowles
2012-02-29 13:43 ` Jesper Nygårds
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CABZhJg9QFx89rSrRhaN8UPNpbfsKHGQbAVJhzYGT+05PYeRR=g@mail.gmail.com' \
--to=jesper.nygards@gmail.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).