zsh-users
 help / color / Atom feed
* Questions from zshexpn(1) -- Globbing
@ 2019-11-19  0:53 ` Perry Smith
  2019-11-19  9:35   ` Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: Perry Smith @ 2019-11-19  0:53 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1.1: Type: text/plain, Size: 902 bytes --]

Again, trying to read through and understand zshexpn…

https://www.mankier.com/1/zshexpn#Filename_Generation-Globbing_Flags <https://www.mankier.com/1/zshexpn#Filename_Generation-Globbing_Flags>

The subsection is Globbing Flags within Filename Generation with both the b and m flags is a curious phrase:

> Activate backreferences for parenthesised groups in the pattern; this does not work in filename generation.

Why does it say “this does not work in filename generation” ?  Using their example for the m flag:

>                      arr=(veldt jynx grimps waqf zho buck)
>                      print ${arr//(#m)[aeiou]/${(U)MATCH}}

I can change the “print” to “touch” and it touches the files and change it to “rm” and it removes the files.

My fear here is that I’m missing something rather significant such as what precisely is “filename generation”


[-- Attachment #1.2: Type: text/html, Size: 1683 bytes --]

<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Again, trying to read through and understand zshexpn…<div class=""><br class=""></div><div class=""><a href="https://www.mankier.com/1/zshexpn#Filename_Generation-Globbing_Flags" class="">https://www.mankier.com/1/zshexpn#Filename_Generation-Globbing_Flags</a></div><div class=""><br class=""></div><div class="">The subsection is Globbing Flags within Filename Generation with both the b and m flags is a curious phrase:</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class="">Activate backreferences for parenthesised groups in the pattern; this does not work in filename generation.</blockquote><br class=""></div><div class="">Why does it say “this does not work in filename generation” ? &nbsp;Using their example for the m flag:</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;arr=(veldt jynx grimps waqf zho buck)<br class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;print ${arr//(#m)[aeiou]/${(U)MATCH}}<br class=""></blockquote><br class=""></div><div class="">I can change the “print” to “touch” and it touches the files and change it to “rm” and it removes the files.</div><div class=""><br class=""></div><div class="">My fear here is that I’m missing something rather significant such as what precisely is “filename generation”</div><div class=""><br class=""></div></body></html>

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 2966 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Questions from zshexpn(1) -- Globbing
  2019-11-19  0:53 ` Questions from zshexpn(1) -- Globbing Perry Smith
@ 2019-11-19  9:35   ` Peter Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2019-11-19  9:35 UTC (permalink / raw)
  To: zsh-users

On Mon, 2019-11-18 at 18:53 -0600, Perry Smith wrote:
> The subsection is Globbing Flags within Filename Generation with both
> the b and m flags is a curious phrase:
>
>> Activate backreferences for parenthesised groups in the pattern;
>> this does not work in filename generation. 
> Why does it say “this does not work in filename generation” ?  Using
> their example for the m flag: 
> 
>>           arr=(veldt jynx grimps waqf zho buck)
>>           print ${arr//(#m)[aeiou]/${(U)MATCH}}
> I can change the “print” to “touch” and it touches the files and
> change it to “rm” and it removes the files. 
> 
> My fear here is that I’m missing something rather significant such as
> what precisely is “filename generation”

You're using that feature in variable substitution, not filename
generation.

Filename generation is specifically the use of pattern characters *, ?,
etc. to generate file names.  So what this means is that the patterns
generated by that method aren't available for use in what I called
backreferences (that's a bad name, sorry: when used in regular
expressions, its standard meaning is references back to a previous part
of the same pattern, which isn't what's happening here).

So if instead of using the array you matched the files directly,
having created them:

    touch $arr
    print (#m)*([aeiou])*

you'd have no way of using the references generated because the file
names are substituted before the $MATCH variable would be available ---
which is probably obvious.

Of course, even if you needed to match the files on the disk first you
could still do

    arr=(*)
    print ${arr//(#m)[aeiou]/${(U)MATCH}}

so you've still got the ability to change the file names with variable
substitution.

So this is probably saying less than you think it is.

pws


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20191119005526eucas1p2f346934679a40e37d2424b3ab6df4cbc@eucas1p2.samsung.com>
2019-11-19  0:53 ` Questions from zshexpn(1) -- Globbing Perry Smith
2019-11-19  9:35   ` Peter Stephenson

zsh-users

Archives are clonable: git clone --mirror http://inbox.vuxu.org/zsh-users

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.users


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git