Assuming you're using GNU utilities, you can do something similar like this:
find $1 -name '*.flac' -print0 | xargs -0 echo
The ``-print0'' option to find tells it to separate its output with null characters instead of spaces, and the ``-0'' option to xargs tells it to expect input separated by null characters. It'll, unfortunately, be a pain to incorporate that into a script. The easiest thing to do would be to then call a new script from xargs, but that will add shell startup time.
Ooh! Here's an idea. Reset IFS to the null character (same as Ctrl-
@
) and then use find's ``-print0'':
OLD_IFS=$IFS
IFS="^@"
for i in `find $1 -name '*.flac' -print0`; do
echo $i
done
IFS=$OLD_IFS
Whatever you call instead of echo might depend on IFS being set to something more sane, though, so you might need to reset it before calling it. You might also need to find some way of getting that null character into IFS without embedding the binary 0x00. Some ideas include
IFS=`echo "x\c" | tr x \\000`
or
IFS=`printf "\000"`
You could also try using perl. I have the feeling it might be a little more forgiving than a Korn-type shell.