Dear Future Me,

Are you trying to iterate over filenames with spaces in them using a bash ‘for’ loop?  And instead of iterating over the filenames, you wind up seeing a list of filename parts split by said spaces?  Use case: you want to print out a list of unique extensions for all files in the current directory and below:

    for file in `find . -type f`; do echo ${file##*.}; done | sort | uniq

If any filenames have spaces in them, you may see odd results.  The answer?  Set the input field separator (IFS) environment variable to the newline character (rather than the default space character):

    export IFS=$'\n'

And voila.

Updated: