Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Glob problem
- X-seq: zsh-users 18051
- From: Yuya Amemiya <ghostrevery@xxxxxxxxx>
- To: brent.briggs@xxxxxxxxx
- Subject: Re: Glob problem
- Date: Wed, 23 Oct 2013 05:11:17 +0900 (JST)
- Cc: zsh-users@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:message-id:to:cc:subject:from:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=mC2ayS7lypYtWOIfZpf6DjhPbg1RhDuDKB79kPUUPKU=; b=o+D6GV7JAfzDyYwTdf8+FsE+J677RSzCHzm8qmJE9JMNK8Q4a8DCuN+u6h3zcahbpj 4XVnhadyLLVWO2z1lCdP5m0NEvVUMphPAoTxdLiq9yjrRcEOad4qWSkhGQU0kwRw3HTx nRa+EelDDc4eOu0zBFo/0tmR562kSkCgtvwoNXT31D5UPgqd9FXt+ScUZaDQyWNKSrlF q9Ex9cqkhGXEImqcrc5nNSEpKeXzylQwFZCu2jGPBOlr8XtEUWP5eN3Fr1JPTUDAxZ10 9ZtwA9AB42D4ZW6V56tjMla8wQHS2BPAI22C0YmJfTJBHkprV2RTtf930b3yK7ELS+XG JlsQ==
- In-reply-to: <F450529B-46FF-4267-B1A3-01E291221268@gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <65DB21EB-86B6-479C-8F25-35B9B832CFD5@gmail.com> <5266BFF6.4050004@oracle.com> <F450529B-46FF-4267-B1A3-01E291221268@gmail.com>
Hi,
> print -l $path/$~pattern
Try this:
print -l -- ${^path}/${~pattern}
regards
From: Brent Briggs <brent.briggs@xxxxxxxxx>
Subject: Re: Glob problem
Date: Tue, 22 Oct 2013 14:49:13 -0400
> Adding the (N) Glob Qualifier made a difference but is I'm still not quite there yet.
>
> pattern=git*(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?
>
> Trying this gets me a little closer.
>
> pattern=git*(N)
> 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
> -- 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 <peter.d.miller@xxxxxxxxxx> 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.
>>>
>>> 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<phil@xxxxxxxx> 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.
>>>>
>>
>
Messages sorted by:
Reverse Date,
Date,
Thread,
Author