【问题标题】:Get confused about square brackets in Bash对 Bash 中的方括号感到困惑
【发布时间】:2014-03-04 03:27:49
【问题描述】:

正如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

谁能给我解释一下?谢谢!

【问题讨论】:

    标签: linux bash shell wildcard


    【解决方案1】:

    这是正确的行为。

    ls [bd]
    

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

    要进一步测试,您可以这样做:

    touch b/foo
    ls [bd]
    

    哪个会给出输出

    foo
    

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

    【讨论】:

    • 哦,就是这样!谢谢你的回答
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-12
    • 1970-01-01
    • 2016-05-19
    • 1970-01-01
    • 2013-07-27
    • 1970-01-01
    • 2012-01-08
    相关资源
    最近更新 更多