bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: globstar question


From: Chet Ramey
Subject: Re: globstar question
Date: Mon, 1 May 2017 09:07:09 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.0.1

On 4/29/17 11:22 PM, L A Walsh wrote:
> 
> 
> Chet Ramey wrote:
>> On 4/28/17 8:09 PM, L A Walsh wrote:
>>> ls **Tokyo*
>>> (nothing)
>>> ls ***Tokyo*
>>> (nothing)
>>> ls **Tokyo**Tokyo*
>>> (nothing)
>>> ls **/*Tokyo*
>>> (found multiple matches (including the one I was
>>> searching for))
>>>     
>>
>> Because the first two search for files containing the string `Tokyo' in the
>> current directory and the third finds files containing `Tokyo' twice.
>>   
> ----
>    So '**' is only special when it's a token by itself?

No. A token is something else: an individual syntactic unit for the parser.
But you're on the right track.

I wish you hadn't deleted the part of my reply that explained this, but
let's see if I can do a better job. We won't use the term `pattern', since
that can have multiple interpretations. We'll use `slug'. The following
tries to explain how slugs are treated when globstar is enabled. Slugs
always act recursively.

A pattern is the entire word to be expanded. A slug is the two-character
string `**'.

If the entire pattern consists of a single slug, the pattern expands to all
files in the current directory and all files in all subdirectories.

If a slug appears in the pattern delimited by a trailing slash, it expands
to all directories and matches files matching the remainder of the pattern.

If a slug appears in the pattern delimited by a preceding slash, it matches
all files and directories that have the preceding part of the pattern as a
prefix.

If a slug appears in the pattern with preceding and trailing slashes, it
matches all files and directories that have the preceding part of the
pattern as the prefix and match the remainder of the pattern.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]