Recursively iterating through files in a directory can easily be done by:
find . -type f -exec bar {} \;
However, the above does not work for more complex things, where a lot of conditional branches, looping etc. needs to be done. I used to use this for the above:
while read line; do [...]; done < <(find . -type f)
However, it seems like this doesn't work for files containing obscure characters:
$ touch $'a\nb'
$ find . -type f
./a?b
Is there an alternative that handles such obscure characters well?
find ... -exec bash -c 'echo filename is in \$0: "$0"' {} \;
is a better way to do it. – jw013 Jun 26 '14 at 14:08read line
toIFS= read -r line
. The only character that will break it then is a newline. – phemmer Jun 26 '14 at 14:43-d $'\0'
is preferable. – godlygeek Jun 26 '14 at 15:14