From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18194 invoked by alias); 24 Feb 2012 07:11:46 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 16783 Received: (qmail 6169 invoked from network); 24 Feb 2012 07:11:35 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED,RCVD_IN_DNSWL_LOW, T_DKIM_INVALID,T_TO_NO_BRKTS_FREEMAIL autolearn=no version=3.3.2 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 209.85.213.43 as permitted sender) Received-SPF: pass (google.com: domain of jesper.nygards@gmail.com designates 10.236.78.201 as permitted sender) client-ip=10.236.78.201; Authentication-Results: mr.google.com; spf=pass (google.com: domain of jesper.nygards@gmail.com designates 10.236.78.201 as permitted sender) smtp.mail=jesper.nygards@gmail.com; dkim=pass header.i=jesper.nygards@gmail.com 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= MIME-Version: 1.0 Date: Fri, 24 Feb 2012 08:11:29 +0100 Message-ID: Subject: Filtering an array From: =?ISO-8859-1?Q?Jesper_Nyg=E5rds?= To: zsh-users@zsh.org Content-Type: text/plain; charset=ISO-8859-1 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?