有没有办法让find
执行我在shell中定义的函数?
例如:
dosomething () {
echo "Doing something with $1"
}
find . -exec dosomething {} \;
其结果是:
find: dosomething: No such file or directory
有没有办法让find
的-exec
看到dosomething
?
有没有办法让find
执行我在shell中定义的函数?
例如:
dosomething () {
echo "Doing something with $1"
}
find . -exec dosomething {} \;
其结果是:
find: dosomething: No such file or directory
有没有办法让find
的-exec
看到dosomething
?
因为只有shell知道如何运行shell函数,所以必须运行shell才能运行函数.您还需要将导出函数标记为export -f
,否则子shell将不会继承它们:
export -f dosomething
find . -exec bash -c 'dosomething "$0"' {} \;