我正在尝试将文件从一个扩展名批量重命名为另一个(背景:在我的 rails 应用程序中使用 haml 而不是 erb)。发出重命名命令时,我得到以下输出:
% zmv '**/*.erb' $1.haml
zmv: error(s) in substitution:
app/views/l/links/index.html.erb and app/views/index/index.html.erb both map to .haml
app/views/l/links/new.html.erb and app/views/l/links/index.html.erb both map to .haml
app/views/l/links/show.html.erb and app/views/l/links/new.html.erb both map to .haml
app/views/l/links/stats.html.erb and app/views/l/links/show.html.erb both map to .haml
app/views/layouts/application.html.erb and app/views/l/links/stats.html.erb both map to .haml
app/views/u/profiles/_form.erb and app/views/layouts/application.html.erb both map to .haml
app/views/u/profiles/edit.html.erb and app/views/u/profiles/_form.erb both map to .haml
app/views/u/profiles/show.html.erb and app/views/u/profiles/edit.html.erb both map to .haml
app/views/u/user_sessions/new.html.erb and app/views/u/profiles/show.html.erb both map to .haml
app/views/u/users/_form.erb and app/views/u/user_sessions/new.html.erb both map to .haml
app/views/u/users/new.html.erb and app/views/u/users/_form.erb both map to .haml
app/views/u/users/show.html.erb and app/views/u/users/new.html.erb both map to .haml
Run Code Online (Sandbox Code Playgroud)
谁能指出我解决这个问题的正确方向?
我认为你真正想要的是这样的:
% zmv '(**/)(*).erb' '$1/$2.haml'
# ^$1 ^$2
Run Code Online (Sandbox Code Playgroud)
您需要使用括号来创建匹配组,然后为文件路径创建一个匹配组,然后为文件名创建一个匹配组。此外,您需要确保 zmv 的第二个参数也在单引号中。
此外,在运行 zmv 命令之前使用“-n”测试它们是一个非常好的主意(-n 会告诉您将重命名的内容,但实际上不会重命名任何内容。)