Project

General

Profile

Actions

Bug #17283

closed

Why does Dir.glob's ** match files in current directory?

Added by Yanir (Yanir Tsarimi) over 3 years ago. Updated over 3 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x64-mingw32]
[ruby-core:100525]

Description

If my current directory has 1 file and 1 dir, and I use Dir.glob("**/*") or even just **, both the dir and the file would be matched.

I would expect that only the dir will be matched, since the glob starts with **, which wants to match a directory.
This is a behavior that's different from bash. In bash only the directory would be matched.

Ruby:

 Directory of C:\Users\User\z

10/24/2020  10:42 PM    <DIR>          .
10/24/2020  10:42 PM    <DIR>          ..
10/24/2020  10:42 PM    <DIR>          dir
10/24/2020  10:41 PM                 4 file
               1 File(s)              4 bytes
               3 Dir(s)  256,993,574,912 bytes free

C:\Users\User\z>irb
irb(main):001:0> Dir.glob("**/*")
=> ["dir", "file"]
irb(main):002:0> Dir.glob("**")
=> ["dir", "file"]

In Bash:

root@debian:~/rubytest# ls -lah
total 12K
drwxr-xr-x  3 root root 4.0K Oct 23 17:44 .
drwx------ 19 root root 4.0K Oct 23 17:43 ..
drwxr-xr-x  2 root root 4.0K Oct 23 17:44 dir
-rw-r--r--  1 root root    0 Oct 23 17:44 file
root@debian:~/rubytest# ls -lah **/*
-rw-r--r-- 1 root root 0 Oct 23 17:44 dir/subfile

I know the behavior is not meant to be 1:1 to bash. But this is still unexpected and doesn't make sense to me. Is this intended?

The documentation says:

**
Matches directories recursively.

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #17280: Dir.glob with FNM_DOTMATCH matches ".." and "." and results in duplicated entriesClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0