From: Brent Briggs <brent.briggs@gmail.com>
To: Philippe Troin <phil@fifi.org>
Cc: zsh-users@zsh.org
Subject: Re: Glob problem
Date: Tue, 22 Oct 2013 14:02:19 -0400 [thread overview]
Message-ID: <65DB21EB-86B6-479C-8F25-35B9B832CFD5@gmail.com> (raw)
In-Reply-To: <1382461534.20462.9.camel@air.home.fifi.org>
[-- Attachment #1: Type: text/plain, Size: 2079 bytes --]
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
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 <phil@fifi.org> 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.
>
[-- Attachment #2: Message signed with OpenPGP using GPGMail --]
[-- Type: application/pgp-signature, Size: 841 bytes --]
next prev parent reply other threads:[~2013-10-22 18:02 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-22 16:45 Brent Briggs
2013-10-22 16:58 ` Jérémie Roquet
2013-10-22 16:59 ` Peter Stephenson
2013-10-22 17:05 ` Philippe Troin
2013-10-22 18:02 ` Brent Briggs [this message]
2013-10-22 18:12 ` Peter Miller
2013-10-22 18:49 ` Brent Briggs
2013-10-22 19:30 ` Peter Miller
2013-10-22 20:11 ` Yuya Amemiya
2013-10-23 12:27 ` Brent Briggs
2013-10-23 12:37 ` Jérémie Roquet
2013-10-23 13:47 ` Peter Stephenson
2013-10-23 14:29 ` Yuya Amemiya
2013-10-22 17:11 ` Matt Garriott
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=65DB21EB-86B6-479C-8F25-35B9B832CFD5@gmail.com \
--to=brent.briggs@gmail.com \
--cc=phil@fifi.org \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).