在bash脚本中,我们可以通过:
shopt -s extglob
为后续代码提供通配功能。
但如果在block中设置,将不会生效。如:
if true; thenshopt -s extglob...
fi
这是因为:
you cannot put shopt -s extglob inside a statement block that uses extended globs, because the block as a whole must be parsed when it’s defined; the shopt command won’t take effect until the block is evaluated, at which point it’s too late.