use internal function with find command

Hi,

I need to use a function in the find command to do some process on the file. I'm trying:

funcname(){ ... }
...
find ./ -name "*" -exec funcname {} \;

But somehow this is not working. I don't want to have a separate script for whatever processing the function does. I want to have both the function and the find command in the same script.

Is there anyway I can put both of them in the same script.

Thanks.
Victor

-exec of find and xargs expect an executable, a command, not a shell script function afaik. So maybe you assign the output of the find to some variable and hand it over as positional parameter for your function instead.

Example:

myfunc()
{
        echo "This is it: $*"
}

VAR=`find . -type f -print`

myfunc $VAR
1 Like