bash: glob 否定和多重模式的问题

bash: Problems with glob negation and multiple patterns

我正在尝试编写一个 glob 模式,该模式 returns 不以 2 个可能后缀之一结尾的文件列表:done 和 monthly

我的测试目录中的文件列表是:

foo.done
foo.montly
foo.pdf
foo.txt

如果我只对 1 个后缀执行否定,我就完全成功了:

ls  !(*done) or ls  !(*monthly)

然而,当我尝试这样的事情时:

ls  !({*monthly,*done})

我明白了:

foo.done
foo.monthly
foo.pdf
foo.pdf
foo.txt
foo.txt

谁能帮我理解一个结果,它不仅在否定方面没有产生我想要的结果,而且还列出了重复项!

使用|分隔模式列表中的模式(docs):

If the extglob shell option is enabled using the shopt builtin, several extended pattern matching operators are recognized. In the following description, a pattern-list is a list of one or more patterns separated by a ‘|’.

结果:

$ shopt -s extglob

$ ls
foo.done  foo.monthly  foo.pdf  foo.txt

$ ls *.!(monthly|done)
foo.pdf  foo.txt