通配符处理

当没有任何东西与 bash 中的*这样的通配符匹配时,它会作为文字*传递给命令,就好像你输入了\*一样。但是,zsh 会抛出错误。

击:

 placeholderCopyduncan@K7DXS-Laptop-Arch:~/test$ echo *.txt
*.txt
duncan@K7DXS-Laptop-Arch:~/test$ touch abc.txt
duncan@K7DXS-Laptop-Arch:~/test$ echo *.txt
abc.txt
duncan@K7DXS-Laptop-Arch:~/test$

岩组:

 placeholderCopyK7DXS-Laptop-Arch% echo *.txt   
abc.txt
K7DXS-Laptop-Arch% rm abc.txt 
K7DXS-Laptop-Arch% echo *.txt
zsh: no matches found: *.txt
K7DXS-Laptop-Arch%

这在使用文字*的程序中最为明显,例如 find:

 placeholderCopyduncan@K7DXS-Laptop-Arch:~/test$ ls -R
.:
abc

./abc:
123.txt

击:

 placeholderCopyduncan@K7DXS-Laptop-Arch:~/test$ find -name *.txt
./abc/123.txt
duncan@K7DXS-Laptop-Arch:~/test$

岩组:

 placeholderCopyK7DXS-Laptop-Arch% find -name *.txt
zsh: no matches found: *.txt
K7DXS-Laptop-Arch% find -name \*.txt
./abc/123.txt
K7DXS-Laptop-Arch% find -name '*.txt' # Notice single rather than double quotes
./abc/123.txt
K7DXS-Laptop-Arch%