Given is a set of files in (sub)directories matching a string like in e.g.:
find -name 'string' | sort
./1/2/3/4/string
./1/2/3/string
./1/2/string
./1/string
./string
Why does using globstar
to match the files like in
ls **string
string
fail to run through the directories, while
ls **/string
1/2/3/4/string 1/2/3/string 1/2/string 1/string string
succeeds? From my understanding of the description in the man
pages it should be matching (sub)directories, shuldn't it?
Question like this usually are marked as duplicate of "The result of ls * , ls ** and ls ***", yet the answer there only handles ls **
, which indeed does recurse through directories. It seems as if a double asterisk followed by a string would break globstar
.
Running GNU bash v.4.4.19(1)
on mint 19
From man bash
globstar
If set, the pattern ** used in a pathname expansion context will match all files and zero or more directories and subdirectories. If the pattern is followed by a /, only directories and subdirectories match.
glob_filename
in lib/glob/glob.c) specifically checks for**/
(and not**
) in several places. ( Search forfilename[1] == '*'
) – Jeff Schaller Oct 10 '18 at 12:25