Results of find cannot be encapsulated in quotes On Linux, handling spaces when I am using the results find only requires wrapping the variable in quotes. This doesn't work on OS X. This code, for example, doesn't work:

for file in $(find . -name "*.txt")
do
    ls -l "${file}"
done


Even wrapped in quotes, parts of file names separated by spaces are treated as their own result. How do I fix this?
From Bash Pitfalls (which also explains in detail why for file in (find ...); do doesn't work):

When using find use it properly eg. use -exec
find . -type f -exec some command {} \;

Instead of ls consider,
for i in *.mp3; do    # Better! and...
    some command &quot;$i&quot; # ...always double-quote expansions!
done

POSIX shells such as Bash have the globbing feature specifically for this purpose -- to allow the shell to expand patterns into a list of matching filenames. There is no need to interpret the results of an external utility. Because globbing is the very last expansion step, each match of the *.mp3 pattern correctly expands to a separate word, and isn't subject to the effects of an unquoted expansion. (If you need to process files recursively, see UsingFind.)
Question: What happens if there are no *.mp3-files in the current directory? Then the for loop is executed once, with i=&quot;*.mp3&quot;, which is not the expected behavior! The workaround is to test whether there is a matching file:
# POSIX
for i in *.mp3; do
    [ -e &quot;$i&quot; ] || continue
    some command &quot;$i&quot;
done

Note the quotes around $i in the loop body above.