给出了一个包含文件的目录$HOME/foo/
。通过变量传递命令'find -exec'不起作用
命令:
find $HOME/foo -type f -exec md5deep -bre {} \;
正常工作和散列文件。
但是,创造-exec
变量似乎并没有工作:
md5="md5deep -bre"
find $HOME/foo -type f -exec "$md5" {} \;
回报:find: md5deep -bre: No such file or directory
为什么呢?
如果要减少命令长度,最好创建一个函数或脚本并将其作为'-exec'的一部分运行。就像'find $ HOME/foo -type f -exec ./md5.sh {} \;' –
@JonathaDaguerre函数不会与'-exec'一起使用,因为它是由'find'执行的,函数只有可用在壳里。 (但一个帮手脚本可以正常工作。) –
好点@GordonDavisson!要从'-exec'运行一个函数,它需要一个新的shell调用。谢谢你纠正我。 –