对Bash中的方括号感到困惑

时间:2014-03-04 03:27:50

标签: linux bash shell wildcard

正如document所述,Bash中的[set]可以匹配set中的任何字符,

在下面,我有3个目录在当前目录中称为a,b,c:


$ ls
a b c

$ ls [abd] # just as expected,show dirs a and b
a:

b:

$ ls [bd] # expecting show dir b but noting matched

$ ls [ad] # expecting show dir a but noting matched

有人可以向我解释一下吗?谢谢!

1 个答案:

答案 0 :(得分:4)

这是正确的行为。

ls [bd]

打印目录b内的文件,该文件为空。

要进一步测试,您可以:

touch b/foo
ls [bd]

哪个会提供输出

foo

PS:但是当您执行ls [abc]时,在第一个命令中,当前路径中有多个匹配的目录 ab因此您获得了输出如你的问题所示。

相关问题