答案1
简单来说,通配符是指模式匹配。Bash 使用简单的通配符,例如,echo l*
它扩展为当前目录中以字母 开头的文件列表l
。当然,正如你所猜测的,它很简单,功能有限。
输入extglob
。正如您所猜到的,它代表extended globbing
。此选项允许更高级的模式匹配。从man bash
:
extglob If set, the extended pattern matching features described
above under Pathname Expansion are enabled.
在此之前:
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 |. Composite patterns may be formed using one or more of the
following sub-patterns:
?(pattern-list)
Matches zero or one occurrence of the given patterns
*(pattern-list)
Matches zero or more occurrences of the given patterns
+(pattern-list)
Matches one or more occurrences of the given patterns
@(pattern-list)
Matches one of the given patterns
!(pattern-list)
Matches anything except one of the given patterns