根据 bash 手册,如果extglob
启用,则模式@(pattern-list)
应匹配pattern-list
(以 分隔|
)中的任何模式。在这里它按预期工作:
$ shopt -s extglob
$ ls -ld /@(.|usr)/@(.|local)/@(.|share)/
drwxr-xr-x 50 root root 4096 Sep 2 16:39 /./././
drwxr-xr-x 12 root root 4096 Oct 15 2018 /usr/././
drwxrwsr-x 10 root staff 4096 Oct 15 2018 /usr/local/./
drwxrwsr-x 10 root staff 4096 Oct 15 2018 /usr/local/share/
drwxr-xr-x 725 root root 20480 Sep 2 16:42 /usr/./share/
Run Code Online (Sandbox Code Playgroud)
但是如果我们在三个模式列表中的每一个中交换替代品,大部分应该匹配的目录都消失了:
$ ls -ld /@(usr|.)/@(local|.)/@(share|.)/
drwxrwsr-x 10 root staff 4096 Oct 15 2018 /usr/local/share/
Run Code Online (Sandbox Code Playgroud)
与不存在的子目录相同。在这里它有效: …