From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1402 invoked by alias); 22 Oct 2013 18:19:19 -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: 18048 Received: (qmail 20804 invoked from network); 22 Oct 2013 18:19:12 -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=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.2 Message-ID: <5266BFF6.4050004@oracle.com> Date: Tue, 22 Oct 2013 14:12:06 -0400 From: Peter Miller Organization: Oracle User-Agent: Mozilla/5.0 (X11; SunOS i86pc; rv:6.0) Gecko/20110814 Thunderbird/6.0 MIME-Version: 1.0 To: Brent Briggs CC: zsh-users@zsh.org Subject: Re: Glob problem References: <1382461534.20462.9.camel@air.home.fifi.org> <65DB21EB-86B6-479C-8F25-35B9B832CFD5@gmail.com> In-Reply-To: <65DB21EB-86B6-479C-8F25-35B9B832CFD5@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Source-IP: userp1040.oracle.com [156.151.31.81] On 10/22/13 14:02, Brent Briggs wrote: > Thanks for all the responses. The glob is now being generated properly. However, I am still having a problem getting my loop to run completely through. > > pattern=git* > for entry in $path > do > print -l $entry/$~pattern > done > > Output: > ---------- > /opt/local/bin/git > /opt/local/bin/git-credential-osxkeychain > /opt/local/bin/git-cvsserver > /opt/local/bin/git-receive-pack > /opt/local/bin/git-shell > /opt/local/bin/git-upload-archive > /opt/local/bin/git-upload-pack > /opt/local/bin/gitk > zsh: no matches found: /opt/local/sbin/git* > > /opt/local/sbin/ being the second entry in my path. > > > Also tried: > > print -l $path/$~pattern try pattern=git*(N) print -l $path/$~pattern that will tell zsh to ignore globs that don't have any matches. > > Output: > ---------- > zsh: no matches found: /Users/brent/bin/git* > > /Users/brent/bin/ being the last entry in my path. > > Looks like I need to use a conditional to test if any pattern matches exist, per directory, before trying to print them. I wasn't able to find a solution in the manual that facilitates testing for the existence of pattern matches. I would like to solve this problem using only globbing if possible. I am probably missing something simple. > > > > On Oct 22, 2013, at 1:05 PM, Philippe Troin wrote: > >> On Tue, 2013-10-22 at 12:45 -0400, Brent Briggs wrote: >> >>> I am simply trying to list all matches for a specified pattern in an >>> array of directory paths, the $path array for example. Here is my >>> attempt. Where am I going wrong? >> Globs are not ran after variable substitution by default. >> To run filename generation (aka globs) after variable substitution, use >> $~var. >> >> Your example: >> >>> pattern=git* >>> for entry in $path >>> do >>> # Print all files in the path that match the pattern. >>> print $entry/$pattern >>> done >> Can be rewritten as: >> >> pattern=git* >> for entry in $path >> do >> # Print all files in the path that match the pattern. >> print $entry/$~pattern >> done >> >> It can be simplified further as: >> >> pattern=git* >> print $path/$~pattern >> >> Phil. >>