From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10380 invoked by alias); 22 Oct 2013 18:49:23 -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: 18049 Received: (qmail 5526 invoked from network); 22 Oct 2013 18:49:19 -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=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=uTzd5rvkijJH1SFpSmT5g4zi7GZ0uErn7cpEc8lB+Rg=; b=iHTsKNU++VSvJH+csG2ZY8ZlSKbDO+38kBnAIPvpldT9pmq+eNo1OqBnmr1vlB88Qb jrk4YK5TB+8q+uXeNh2C4IzzHj2yVuv2ZkBEZM0FoaLGEFDeppizzbAWpxIPednqT4e0 6g/w/W4NQDJwaxx1LRsr57dzGqPOZzYVqoq7avJGX9G719sQn4qW47Cy+wZDtko3dppK yr++jK/xfZRuNJsRuT2HAcdb71HR6BCK7B6utSERRRtLOQUJ2xdkiC1K89FoUXxVTup7 MpB9ogvCNh2MS2QG3LRuVJ39PTX3sBCFdzB4HAiDFK/AB7meP7/bCe5BPFyd1/6ZDNtU iYYA== X-Received: by 10.58.255.233 with SMTP id at9mr5824857ved.20.1382467756493; Tue, 22 Oct 2013 11:49:16 -0700 (PDT) Content-Type: text/plain; charset=iso-8859-1 Mime-Version: 1.0 (Mac OS X Mail 6.6 \(1510\)) Subject: Re: Glob problem From: Brent Briggs In-Reply-To: <5266BFF6.4050004@oracle.com> Date: Tue, 22 Oct 2013 14:49:13 -0400 Cc: zsh-users@zsh.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <1382461534.20462.9.camel@air.home.fifi.org> <65DB21EB-86B6-479C-8F25-35B9B832CFD5@gmail.com> <5266BFF6.4050004@oracle.com> To: Peter Miller X-Mailer: Apple Mail (2.1510) Adding the (N) Glob Qualifier made a difference but is I'm still not = quite there yet.=20 pattern=3Dgit*(N) print -l $path/$~pattern Output: ---------- /opt/local/bin /opt/local/sbin /usr/bin /bin /usr/sbin /sbin /usr/local/bin /usr/local/MacGPG2/bin This is my full path listing minus the final entry /Users/brent/bin. I = know this is a bit of an incidental question but why is the final path = entry missing from this output?=20 Trying this gets me a little closer. pattern=3Dgit*(N) for entry in $path =20 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 -- blank -- /usr/bin/git /usr/bin/git-cvsserver /usr/bin/git-receive-pack /usr/bin/git-shell /usr/bin/git-upload-archive /usr/bin/git-upload-pack -- blank -- -- blank -- -- blank -- -- blank -- -- blank -- Blank lines are printed for the directories that contain no pattern = matches. Any quick way to get rid of these? On Oct 22, 2013, at 2:12 PM, Peter Miller = wrote: > 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. >>=20 >> pattern=3Dgit* >> for entry in $path >> do >> print -l $entry/$~pattern >> done >>=20 >> 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* >>=20 >> /opt/local/sbin/ being the second entry in my path. >>=20 >>=20 >> Also tried: >>=20 >> print -l $path/$~pattern >=20 > try >=20 > pattern=3Dgit*(N) > print -l $path/$~pattern >=20 > that will tell zsh to ignore globs that don't have any matches. >=20 >>=20 >> Output: >> ---------- >> zsh: no matches found: /Users/brent/bin/git* >>=20 >> /Users/brent/bin/ being the last entry in my path. >>=20 >> 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. >>=20 >>=20 >>=20 >> On Oct 22, 2013, at 1:05 PM, Philippe Troin wrote: >>=20 >>> On Tue, 2013-10-22 at 12:45 -0400, Brent Briggs wrote: >>>=20 >>>> 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. >>>=20 >>> Your example: >>>=20 >>>> pattern=3Dgit* >>>> for entry in $path >>>> do >>>> # Print all files in the path that match the pattern. >>>> print $entry/$pattern >>>> done >>> Can be rewritten as: >>>=20 >>> pattern=3Dgit* >>> for entry in $path >>> do >>> # Print all files in the path that match the pattern. >>> print $entry/$~pattern >>> done >>>=20 >>> It can be simplified further as: >>>=20 >>> pattern=3Dgit* >>> print $path/$~pattern >>>=20 >>> Phil. >>>=20 >=20