* Glob problem
@ 2013-10-22 16:45 Brent Briggs
2013-10-22 16:58 ` Jérémie Roquet
` (3 more replies)
0 siblings, 4 replies; 14+ messages in thread
From: Brent Briggs @ 2013-10-22 16:45 UTC (permalink / raw)
To: zsh-users
Hello Zsh masters,
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?
pattern=git*
for entry in $path
do
# Print all files in the path that match the pattern.
print $entry/$pattern
done
Expected/Desired 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
/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
Actual Output:
-------------------
/opt/local/bin/git*
/opt/local/sbin/git*
/opt/local/bin/git*
/opt/local/sbin/git*
/usr/bin/git*
/bin/git*
/usr/sbin/git*
/sbin/git*
/usr/local/bin/git*
/usr/local/MacGPG2/bin/git*
/Users/brent/bin/git*
/Users/brent/bin/git*
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Glob problem
2013-10-22 16:45 Glob problem Brent Briggs
@ 2013-10-22 16:58 ` Jérémie Roquet
2013-10-22 16:59 ` Peter Stephenson
` (2 subsequent siblings)
3 siblings, 0 replies; 14+ messages in thread
From: Jérémie Roquet @ 2013-10-22 16:58 UTC (permalink / raw)
To: Brent Briggs; +Cc: Zsh Users
Hi,
2013/10/22 Brent Briggs <brent.briggs@gmail.com>:
> 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?
>
> pattern=git*
> for entry in $path
> do
> # Print all files in the path that match the pattern.
> print $entry/$pattern
> done
Filename expansion is not done when patterns are stored in variables.
You have to force it using the $~var syntax.
Try this:
print $entry/$~pattern
Best regards,
--
Jérémie
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Glob problem
2013-10-22 16:45 Glob problem 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 17:11 ` Matt Garriott
3 siblings, 0 replies; 14+ messages in thread
From: Peter Stephenson @ 2013-10-22 16:59 UTC (permalink / raw)
To: Brent Briggs, zsh-users
On Tue, 22 Oct 2013 12:45:48 -0400
Brent Briggs <brent.briggs@gmail.com> 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?
I'm sure someone will beat me to it...
> pattern=git*
It's not the source of the problem, but it's generally safer to quote
literal patterns if you don't want them expanded at that point.
Actually, you can't get a glob here unless you have the GLOB_ASSIGN
option set.
> for entry in $path
> do
> # Print all files in the path that match the pattern.
> print $entry/$pattern
> done
$pattern is the literal string "git*" in zsh and doesn't get expanded
further.
If you like the way other shells work, use (globally)
setopt globsubst
However, most of us find it a pain having to remember to quote variables
every time we we want them to be substituted literally (which most other
languages would do automatically).
The zsh-specific way to tell it you want pattern characters to be
special is:
print $entry/${~pattern}
pws
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Glob problem
2013-10-22 16:45 Glob problem 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
2013-10-22 17:11 ` Matt Garriott
3 siblings, 1 reply; 14+ messages in thread
From: Philippe Troin @ 2013-10-22 17:05 UTC (permalink / raw)
To: Brent Briggs; +Cc: zsh-users
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.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Glob problem
2013-10-22 16:45 Glob problem Brent Briggs
` (2 preceding siblings ...)
2013-10-22 17:05 ` Philippe Troin
@ 2013-10-22 17:11 ` Matt Garriott
3 siblings, 0 replies; 14+ messages in thread
From: Matt Garriott @ 2013-10-22 17:11 UTC (permalink / raw)
To: Brent Briggs; +Cc: zsh-users
By default Zsh does not expand glob patterns in variables when using
parameter expansion. You can change this behavior using the GLOB_SUBST
option. Add the following line to the top of your script, and it should
work like you expect.
setopt GLOB_SUBST
For more info check out GLOB_SUBST in `man zshoptions`
-Matt
On Tue, Oct 22, 2013 at 12:45:48PM -0400, Brent Briggs wrote:
> Hello Zsh masters,
>
> 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?
>
> pattern=git*
> for entry in $path
> do
> # Print all files in the path that match the pattern.
> print $entry/$pattern
> done
>
> Expected/Desired 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
> /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
>
> Actual Output:
> -------------------
> /opt/local/bin/git*
> /opt/local/sbin/git*
> /opt/local/bin/git*
> /opt/local/sbin/git*
> /usr/bin/git*
> /bin/git*
> /usr/sbin/git*
> /sbin/git*
> /usr/local/bin/git*
> /usr/local/MacGPG2/bin/git*
> /Users/brent/bin/git*
> /Users/brent/bin/git*
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Glob problem
2013-10-22 17:05 ` Philippe Troin
@ 2013-10-22 18:02 ` Brent Briggs
2013-10-22 18:12 ` Peter Miller
0 siblings, 1 reply; 14+ messages in thread
From: Brent Briggs @ 2013-10-22 18:02 UTC (permalink / raw)
To: Philippe Troin; +Cc: zsh-users
[-- 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 --]
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Glob problem
2013-10-22 18:02 ` Brent Briggs
@ 2013-10-22 18:12 ` Peter Miller
2013-10-22 18:49 ` Brent Briggs
0 siblings, 1 reply; 14+ messages in thread
From: Peter Miller @ 2013-10-22 18:12 UTC (permalink / raw)
To: Brent Briggs; +Cc: zsh-users
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@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.
>>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Glob problem
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
0 siblings, 2 replies; 14+ messages in thread
From: Brent Briggs @ 2013-10-22 18:49 UTC (permalink / raw)
To: Peter Miller; +Cc: zsh-users
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@oracle.com> 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@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.
>>>
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Glob problem
2013-10-22 18:49 ` Brent Briggs
@ 2013-10-22 19:30 ` Peter Miller
2013-10-22 20:11 ` Yuya Amemiya
1 sibling, 0 replies; 14+ messages in thread
From: Peter Miller @ 2013-10-22 19:30 UTC (permalink / raw)
To: Brent Briggs; +Cc: zsh-users
On 10/22/13 14:49, Brent Briggs wrote:
> 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?
I'm sure there is a better way, but this should work:
v=(); for entry in $path; do v+=($entry/$~pattern); done; print -l $v
>
> On Oct 22, 2013, at 2:12 PM, Peter Miller<peter.d.miller@oracle.com> 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@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.
>>>>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Glob problem
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
1 sibling, 1 reply; 14+ messages in thread
From: Yuya Amemiya @ 2013-10-22 20:11 UTC (permalink / raw)
To: brent.briggs; +Cc: zsh-users
Hi,
> print -l $path/$~pattern
Try this:
print -l -- ${^path}/${~pattern}
regards
From: Brent Briggs <brent.briggs@gmail.com>
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@oracle.com> 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@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.
>>>>
>>
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Glob problem
2013-10-22 20:11 ` Yuya Amemiya
@ 2013-10-23 12:27 ` Brent Briggs
2013-10-23 12:37 ` Jérémie Roquet
` (2 more replies)
0 siblings, 3 replies; 14+ messages in thread
From: Brent Briggs @ 2013-10-23 12:27 UTC (permalink / raw)
To: zsh-users
This did the job. I still have one question. I can't find any documentation for the "--" option. What does it do exactly?
On Oct 22, 2013, at 4:11 PM, Yuya Amemiya <ghostrevery@gmail.com> wrote:
> Hi,
>
>> print -l $path/$~pattern
>
> Try this:
> print -l -- ${^path}/${~pattern}
>
> regards
>
> From: Brent Briggs <brent.briggs@gmail.com>
> 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@oracle.com> 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@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.
>>>>>
>>>
>>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Glob problem
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
2 siblings, 0 replies; 14+ messages in thread
From: Jérémie Roquet @ 2013-10-23 12:37 UTC (permalink / raw)
To: Brent Briggs; +Cc: zsh-users
Hi,
2013/10/23 Brent Briggs <brent.briggs@gmail.com>:
> This did the job. I still have one question. I can't find any documentation for the "--" option. What does it do exactly?
Many programs handle this as a flag that says that subsequent
parameters on the command line starting with a dash (“-”) are not
options (while, in general, parameters starting with a dash are
options).
For example:
rm -f # call rm with the “-f” option
rm -- -f # call rm on the “-f” file
This is not zsh-specific.
Best regards,
--
Jérémie
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Glob problem
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
2 siblings, 0 replies; 14+ messages in thread
From: Peter Stephenson @ 2013-10-23 13:47 UTC (permalink / raw)
To: zsh-users
On Wed, 23 Oct 2013 08:27:22 -0400
Brent Briggs <brent.briggs@gmail.com> wrote:
> This did the job. I still have one question. I can't find any
> documentation for the "--" option. What does it do exactly?
It's documented for shell invocation in the zsh manual page, but I don't
see anything about option handling for builtins. There probably should
be something. Some of the regulars can tell me if the following looks
right.
diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo
index 1d9fe68..e9fc7bf 100644
--- a/Doc/Zsh/builtins.yo
+++ b/Doc/Zsh/builtins.yo
@@ -28,6 +28,33 @@ See ifzman(the section `Zle Builtins' in zmanref(zshzle))\
ifnzman(noderef(Zle Builtins)).
)\
)\
+
+Some shell builtin commands take options as given in invidiual entries.
+Typically options are single letters preceded by a hyphen (tt(-)).
+Options that take an argument accept it either immediately following the
+option letter or after white space, for example `tt(print -C3 *)' or
+`tt(print -C 3 *)' are equivalent. Arguments to options are not the
+same as arguments to the command; the documentation indicates which is
+which. Options that do not take an argument may be combined in a single
+word, for example `tt(print -ca *)' and `tt(print -c -a *)' are
+equivalent.
+
+Some shell builtin commands also take options that begin with `tt(+)'
+instead of `tt(-)'. These commands are indicated in the list below.
+
+Options must appear in a group before any non-option arguments;
+once the first non-option argument has been found, option processing is
+terminated.
+
+All builtin commands other than precommand modifiers, even those that
+have no options, can be given the argument `tt(--)' to terminate option
+processing. This indicates that the following words are non-option
+arguments, but is otherwise ignored. This is useful in cases where
+arguments to the command may begin with `tt(-)'. For historical
+reasons, most builtin commands also recognize a single `tt(-)' in a
+separate word for this purpose; note that this is less standard and
+use of `tt(--) is recommended.
+
startitem()
prefix(-)
findex(.)
pws
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Glob problem
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
2 siblings, 0 replies; 14+ messages in thread
From: Yuya Amemiya @ 2013-10-23 14:29 UTC (permalink / raw)
To: brent.briggs; +Cc: zsh-users
Hi,
> This did the job. I still have one question. I can't find any documentation for the "--" option. What does it do exactly?
"--" is not a option.
This separates options and normal arguments to give arguments starting with "-".
The more important point is ${^path}.
This turns on RC_EXPAND_PARAM option for evaluation of path.
${^path}/${~pattern} is substituted with /opt/local/bin/git*(N) /opt/local/sbin/git*(N) ...
and result of substitution is interpreted as pattern for filename generation.
regards,
From: Brent Briggs <brent.briggs@gmail.com>
Subject: Re: Glob problem
Date: Wed, 23 Oct 2013 08:27:22 -0400
> This did the job. I still have one question. I can't find any documentation for the "--" option. What does it do exactly?
>
>
> On Oct 22, 2013, at 4:11 PM, Yuya Amemiya <ghostrevery@gmail.com> wrote:
>
>> Hi,
>>
>>> print -l $path/$~pattern
>>
>> Try this:
>> print -l -- ${^path}/${~pattern}
>>
>> regards
>>
>> From: Brent Briggs <brent.briggs@gmail.com>
>> 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@oracle.com> 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@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.
>>>>>>
>>>>
>>>
>
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2013-10-23 14:30 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-22 16:45 Glob problem 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
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
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).