I am trying to write a script that will apply a bash function for each file in a directory recursively. For example if the directory tests had all my files and sub-directories in it, the script
find tests -type f -print0 | xargs -0 echo
Works perfectly. Now I want to be able to apply a bash function rather than just echo, so I came up with something like this:
function fun() {
echo $1
}
export -f fun
find tests -type f -print0 | xargs -0 bash -c 'fun "$@"'
However this only outputs a single file in tests, where before it output all the files. I would expect these two to run the same no?