Handling filenames with spaces in a bash for or while loop
// The `find` here gets every directory in my home dir, one level deep, but some of them have spaces... the default 'for i in $(find ...)' behavior treats each individual word boundary as a separate variable, but piping to `read` breaks them on newlines
// Note: OS X `find` does not support "-depth 1" (its -depth opt is for depth-first searching vs. breadth-first), just use an 'ls' with an 'if [ -d $filename]' to test for directories
// Note: OS X `find` does not support "-depth 1" (its -depth opt is for depth-first searching vs. breadth-first), just use an 'ls' with an 'if [ -d $filename]' to test for directories
find ~ -type d -depth 1 | while read filename; do # ls ~ | while read filename; do echo $filename # other stuff done