From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7245 invoked by alias); 24 Feb 2012 11:33:44 -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: 16784 Received: (qmail 23677 invoked from network); 24 Feb 2012 11:33:41 -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.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at herrmann-koenigsberg.de does not designate permitted sender hosts) From: Felix Herrmann Subject: Re: Filtering an array To: zsh-users@zsh.org In-Reply-To: References: Message-Id: <20120224102511.6ED931A8532@localhost.localdomain> Date: Fri, 24 Feb 2012 11:25:11 +0100 (CET) X-Provags-ID: V02:K0:ATcR6z/4Hqoh0Dft0ctJiiZ4A5tOCYB+/AekgMGJVAi KeJNaDOq3J33Rs16tQmKvD21ozkQKEx+BPSuH0PZtc6IJnhHfI rWbVCGG82aKMjhqn/z4H+xeSmUMhEuV2OvJXsTR+zXfMoB7VZC zl3a4ek48XoyIHnh+y5LSrFOMA4Ayl2k6d7Eh/Q8beiSY+Gsy1 M/esn8hkIBM9w3f9MCEYdkC8ur/BNSsXwARFBMXXx0eIvp+fBf 7OW40GUfuClPK8kzd0maIgqjdMJ9DtLEfyy3N3zbU9KUZ7s0d0 vFOtpWUTghfAwAUwNN8rUI0lVX1x3k4Cp2wOC9jEwu6dzUyirL Hy13Md92yhQ2qIMQKFcZEyZ2Z3NNh9Z+RPlKYOBH+fq/WqGVvi 8Shkm/dHihMkc3XluBMP8OCQeWtMVfZ5v4= Hi :) On Fri, 24 Feb 2012 08:11:29 +0100, Jesper Nygårds wrote: > 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[...]. I'm no expert at all at zsh-scripts but I think the problem is that myfiles isn't an array anymore after the first iteration. I changed your code to the following: findfiles() { local myfiles myarg myfiles=( **/*$1* ) shift for myarg; do myfiles=(${(M)myfiles:#*$myarg*}) done print $myfiles } There are two little differences here. First of all, I didn't write '$@' in the for-line. If you don't give an 'in x', for iterates over the remaining arguments. The second difference - and the more important one - is, that I put () around the rhs of the myfiles-assignment, to make sure to assign an array to the variable myfiles. I think that was the catch. After this modification, your script works fine :) Greetings, Felix Herrmann.