Memory Matrix

Looping through filenames in Bash

Posted in Computing Notes on January 21st, 2024 and tagged ,
Permalink https://memorymatrix.cloud/archives/22.html

Revised on January 27th, 2026 at 8:19 PM

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