GNU查找手册页指出:
-exec command ; [...] The string `{}' is replaced by the current file name being processed everywhere it occurs in the arguments to the command, not just in arguments where it is alone, as in some versions of find. Both of these constructions might need to be escaped (with a `\') or quoted to protect them from expansion by the shell.
那是从男人到find
(GNU findutils)4.4.2。
现在,我使用bash和dash进行了测试,并且两者都不需要{}
被遮盖。这是一个简单的测试:
find /etc -name "hosts" -exec md5sum {} \;
是否有我确实需要遮盖牙套的外壳?请注意,这并不取决于找到的文件是否包含空白(从bash调用):
find ~ -maxdepth 1 -type d -name "U*" -exec ls -d {} \;
/home/stefan/Ubuntu One
如果将找到的文件传递到子shell,则此更改:
find ~ -maxdepth 3 -type d -name "U*" -exec bash -c 'ls -d {}' \;
ls: cannot access /home/stefan/Ubuntu: No such file or directory
ls: cannot access One: No such file or directory
可以通过以下方法解决:
find ~ -maxdepth 3 -type d -name "U*" -exec bash -c 'ls -d "$0"' {} \;
与:
find ~ -maxdepth 3 -type d -name "U*" -exec bash -c 'ls -d "{}"' \;
/home/stefan/Ubuntu One
但这不是手册页在谈论的,是吗?那么,哪个外壳{}
以不同的方式对待?