找到-exec一个shell功能? [英] find -exec a shell function?

查看:156
本文介绍了找到-exec一个shell功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让找到来执行一个功能我在shell界定?例如:

Is there a way to get find to execute a function I define in the shell? For example:

dosomething () {
  echo "doing something with $1"
}
find . -exec dosomething {} \;

中的结果是:

find: dosomething: No such file or directory

有没有办法让找到的 -exec 的DoSomething < / code>?

推荐答案

由于只有外壳知道如何运行shell的功能,你必须运行一个shell来运行的功能。您还需要与出口-f 标记您的导出功能,否则子shell不会继承他们:

Since only the shell knows how to run shell functions, you have to run a shell to run a function. You also need to mark your function for export with export -f, otherwise the subshell won't inherit them:

export -f dosomething
find . -exec bash -c 'dosomething "$0"' {} \;

这篇关于找到-exec一个shell功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆