Looping through filenames in Bash

January 21st, 2024 – 1:59 am
Categorized as Computing Notes
Tagged as ,

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