To loop through the subdirectories in a folder, when those subdirectories may contain spaces in the file names, use the following procedure.
OLD_IFS=$IFS && IFS=$'\n' for directory in $HOME/somefolder/*/; do echo “some code here” done IFS=$OLD_IFS
To loop through the subdirectories in a folder, when those subdirectories may contain spaces in the file names, use the following procedure.
OLD_IFS=$IFS && IFS=$'\n' for directory in $HOME/somefolder/*/; do echo “some code here” done IFS=$OLD_IFS
Revised on January 27th, 2026 at 8:19 PM