我目前正在编写一个非常简单的 zsh 脚本。我经常做的是这样的:
mv */*.{a,b} .
Run Code Online (Sandbox Code Playgroud)
当我在 zsh 脚本中运行它时,它似乎以不同的方式扩展并在交互模式下工作时失败。
% mkdir dir
% touch dir/file.a
% ls file.a
ls: cannot access file.a: No such file or directory
% mv */*.{a,b} .
% ls file.a
file.a
Run Code Online (Sandbox Code Playgroud)
所以,这有效,但作为脚本:
% mkdir dir
% touch dir/file.a
% ls file.a
ls: cannot access file.a: No such file or directory
% cat script.sh
#!/usr/bin/zsh
mv */*.{a,b} .
% ./script.sh
./script.sh:2: no matches found: */*.b
Run Code Online (Sandbox Code Playgroud)
那么,有什么不同呢?我究竟做错了什么?