Tuesday, February 28, 2023

Bash: Looping Over Filenames With Spaces

 The common:

for F in *; do ...; done

will fail if the files contain whitespace in their names. At least for files with just spaces, this works:

find -iname GLOB | while read F; do
   ....
done

https://stackoverflow.com/questions/7039130/iterate-over-a-list-of-files-with-spaces

 


UPDATE: It appears that newer versions of bash solve this problem and do what expect it to do:

#> for i in h*; do echo $i; done
ho ho

No comments:

Post a Comment

Comments welcome, but they are expected to be civil.
Please don't bother spamming me. I'm only going to delete it.