Alex Rivera | Logout

'find -exec' a shell function in Linux

Asked 2010-12-01T05:25:34.680
280

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 {} \;

The result of that is:

find: dosomething: No such file or directory

Is there a way to get find's -exec to see dosomething?

Edit
Report

1 Answer

0

Not directly, no. Find is executing in a separate process, not in your shell.

Create a shell script that does the same job as your function and find can -exec that.

answered 2010-12-01T05:27:57.737

Your Answer