Welcome

Apologia, decisions, & consequences

Navigation

Blogroll

Tags

Looping through filenames in Bash

January 21st, 2024 by Mr. Lynx Economicus   URI: https://memorymatrix.cloud/archives/22.html

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

 

Posted in Computing Notes | Tagged: ,