Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Filtering an array
- X-seq: zsh-users 16783
- From: Jesper Nygårds <jesper.nygards@xxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Filtering an array
- Date: Fri, 24 Feb 2012 08:11:29 +0100
- Authentication-results: mr.google.com; spf=pass (google.com: domain of jesper.nygards@xxxxxxxxx designates 10.236.78.201 as permitted sender) smtp.mail=jesper.nygards@xxxxxxxxx; dkim=pass header.i=jesper.nygards@xxxxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; bh=ysyAyVf77B6a/YBjVDiS/3Jk3Xq7WcsK9v41SgMLcmc=; b=MqyfDzzhLkDxVZ/VVGRsg5MFy0oKN6a3EJsf9ythRruvf+bOlK4HnBNO+sr5DsjH9/ ZWf/OxJPsuLjwS/l1fYn9ghm8eNx36jCIbizNbOoM4olCXSO+/M6mL+3c2SBzqAt2Jdl 5r/aJVbOoDHw+Ee6EqQHFT5VPUnLIa8uiMDhI=
- 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
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