find -exec 在鱼中不起作用

Dar*_*awg 7 find fish

在使用 fish 作为我的 shell 时,我尝试使用以下命令设置对当前目录中的一堆 c 源文件的权限

find . -type f -name "*.c" -exec chmod 644 {} +;
Run Code Online (Sandbox Code Playgroud)

我收到一个错误

查找:缺少`-exec'的参数

或者

find . -type f -name "*.c" -exec chmod 644 {} \;
Run Code Online (Sandbox Code Playgroud)

我收到一个错误

chmod: 无法访问 '': 没有那个文件或目录

怎么了?

Sté*_*las 17

fish恰好是少数{}需要引用的shell 之一

因此,使用该外壳,您需要:

find . -type f -name '*.c' -exec chmod 644 '{}' +
Run Code Online (Sandbox Code Playgroud)

未引用时,{}扩展为空参数,因此命令变为:

find . -type f -name '*.c' -exec chmod 644 '' +
Run Code Online (Sandbox Code Playgroud)

find抱怨丢失{}(或;+只公认为-exec以下时终止{})。

对于大多数其他 shell,您不需要{}.