$ mkdir temp && cd temp
$ ls [0-9]
ls: cannot access '[0-9]': No such file or directory
$ touch \[0-9\]
$ ls [0-9]
'[0-9]'
$ touch 1
$ ls
1 '[0-9]'
$ ls [0-9]
1
Run Code Online (Sandbox Code Playgroud)
我觉得这种行为非常令人惊讶。对我来说,[0-9]
glob 模式应该只匹配名称由单个数字组成的文件。但它有时也会匹配一个名为[0-9]
自身的文件。
这是 bash 中 glob 扩展的错误吗?
我可以禁用它,以便[0-9]
永远不匹配[0-9]
(因为它不应该)?