萬用字元處理

當沒有任何東西與 bash 中的*這樣的萬用字元匹配時,它會作為文字*傳遞給命令,就好像你輸入了\*一樣。但是,zsh 會丟擲錯誤。

擊:

duncan@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$ 

巖組:

K7DXS-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:

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

./abc:
123.txt

擊:

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

巖組:

K7DXS-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%