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: Fri, 28 Apr 2017 22:02:50 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.0.1

On 4/28/17 8:09 PM, L A Walsh wrote:
> 
> I wanted to search for a file that had 'Tokyo' in the basename,
> in all directories below a given point.  I had been doing it 'find',
> but thought globstar should work.
> W/globstar set, I looked for:
> 
> ls **Tokyo*
> (nothing)
> ls ***Tokyo*
> (nothing)
> ls **Tokyo**Tokyo*
> (nothing)
> ls **/*Tokyo*
> (found multiple matches (including the one I was
> searching for))
> 
> A sample file I was searching for:
> 
> Library/Tokyo Ravens/[gg]_Tokyo_Ravens_-_01_[398DE7BC].mkv
> 
> I.e. had Tokyo in _both_, dir and subfiles,
> Why didn't any of the 1st 3 patterns find anything?

Because the first two search for files containing the string `Tokyo' in the
current directory and the third finds files containing `Tokyo' twice.

> It seemed that I needed a '/' in the pattern for it
> to be processed as a globstar pattern...??
> 
> Is that supposed to be a requirement for globstar
> to function?  From this (from bash manpage):

Yes.  This is what "used as a single pattern" means.  When used for
pathname expansion, patterns are individual strings of characters,
and slashes separate patterns.  So the `**Tokyo*' is a single pattern,
`***Tokyo*' is a single pattern, and so on, while `**/*Tokyo*' is two
patterns, one of which is `**'.  So `**' needs to appear as a pattern
by itself, either as the string `**' or as one of the patterns separated
by slashes, to get the behavior you want.

> 
>  *      Matches any string, including the null string.  When  the
>         globstar  shell  option  is  enabled,  and * is used in a
>         pathname expansion context, two adjacent  *s  used  as  a
>         single  pattern  will  match  all  files and zero or more
>         directories and subdirectories.  If followed by a /,  two
>         adjacent  *s  will match only directories and subdirecto-
>         ries.


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



reply via email to

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