使用“**”模式的递归 glob.glob 出现意外结果

Luc*_*ams 6 python glob

不存在的目录上的递归 glob 结果:

>>> import os, glob
>>> os.path.exists('dir')
False

>>> glob.glob('dir/*', recursive=True)
[]

>>> glob.glob('dir/**', recursive=True)
['dir/']

Run Code Online (Sandbox Code Playgroud)

现有文件的递归 glob 结果作为目录返回:

>>> os.path.exists('file')
True

>>> glob.glob('file/*', recursive=True)
[]

>>> glob.glob('file/**', recursive=True)
['file/']

Run Code Online (Sandbox Code Playgroud)

使用 bash shell 补全的类似命令将产生以下输出:

$ shopt -s globstar failglob

$ ls dir
ls: cannot access 'dir': No such file or directory
$ echo dir/*
-bash: no match: dir/*
$ echo dir/**
-bash: no match: dir/**

$ touch file
$ echo file/*
-bash: no match: file/*
$ echo file/**
-bash: no match: file/**
Run Code Online (Sandbox Code Playgroud)

对于以“**”模式返回的全局结果有任何逻辑解释还是只是一个错误?