小编jhr*_*jhr的帖子

zsh 扩展在非交互式脚本中的工作方式是否不同?

我目前正在编写一个非常简单的 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)

那么,有什么不同呢?我究竟做错了什么?

shell scripting zsh wildcards

3
推荐指数
1
解决办法
1171
查看次数

标签 统计

scripting ×1

shell ×1

wildcards ×1

zsh ×1