Categories
linux tech

Correct Way To Iterate Over Files In Bash

Because I keep forgetting, here’s a reminder to myself of the correct way to iterate through files and directories in bash, even considering spaces in filenames, whith a hat-tip to Thomas Howard Uphill:

find . -type f|grep .ext$ |while read file
do
/do/something/to "$file"
done

Silly rabbit.

By Rob Hallam

Glasgow University graduate. I have wide-ranging interests - please see my about page either here or at roberthallam.com.

3 replies on “Correct Way To Iterate Over Files In Bash”

Tell us what's on your mind