在阅读了有关扩展的 glob 后,我有一个问题。
使用后shopt -s extglob
,
以下有什么区别?
?(list): Matches zero or one occurrence of the given patterns.
*(list): Matches zero or more occurrences of the given patterns.
+(list): Matches one or more occurrences of the given patterns.
@(list): Matches one of the given patterns.
Run Code Online (Sandbox Code Playgroud)
是的,我已经阅读了伴随它们的上述说明,但出于实际目的,我看不出人们更喜欢 ?(list) 而非 *(list) 的情况。也就是说,我看不出任何区别。
我尝试了以下方法:
$ ls
> test1.in test2.in test1.out test2.out`
$ echo *(*.in)
> test1.in test2.in
$ echo ?(*.in)
> test1.in test2.in
Run Code Online (Sandbox Code Playgroud)
我希望仅从描述中$ echo ?(*.in)
输出test1.in
,但情况似乎并非如此。因此,任何人都可以举一个例子,说明它对使用的扩展 glob 的类型产生影响吗?
来源:http : //mywiki.wooledge.org/BashGuide/Patterns#Extended_Globs
$ shopt -s extglob
$ ls
abbc abc ac
$ echo a*(b)c
abbc abc ac
$ echo a+(b)c
abbc abc
$ echo a?(b)c
abc ac
$ echo a@(b)c
abc
Run Code Online (Sandbox Code Playgroud)