Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
一个目录下有三个文件:
ab2 ab23 ab3
当我执行时:
ls ab+(2|3)
它显示:
而不是ab2且ab3仅。
ab2
ab3
任何想法为什么会这样?它是一个错误吗?
这不是一个错误。+(pattern)匹配一次或多次出现的模式。+(2|3)将匹配任意组合和任意数量的2's 和3's: 2, 3, 23, 32, 222, 333, 3223232323——其中任何一个。
+(pattern)
+(2|3)
2
3
23
32
222
333
3223232323
如果您想要严格交替而不重复,请更改+为@:
+
@
ab@(2|3)
(或者只是使用ab[23]。那甚至不需要extglob。)
ab[23]
extglob