This classical solution (when there are only spaces in the names) didn't work
find . -name '*.html' -print0 | while IFS= read -r -d ''; do
because the html files additionally contain vertical lines (|
).
This classical solution (when there are only spaces in the names) didn't work
find . -name '*.html' -print0 | while IFS= read -r -d ''; do
because the html files additionally contain vertical lines (|
).
find . -name '*.html' -print0 | while IFS= read -r -d ''; do
There is nothing on that line that would have any sort of problems with filenames containing combinations of spaces and/or pipes in their names:
bash-4.4$ touch 'A|B' '1|2' 'quux|foo bar'
bash-4.4$ ls
1|2 A|B quux|foo bar
bash-4.4$ find . -print0 | while IFS= read -r -d ''; do printf '"%s"\n' "$REPLY"; done
"."
"./A|B"
"./1|2"
"./quux|foo bar"
Notice too that depending on what you'd like to do with the found names, it almost always better to do that with an -exec
from within find
itself:
find . -type f -name "A*" -exec cat {} \;
Related answer to another question: Why does my shell script choke on whitespace or other special characters? (see especially "How do I process files found by find?" in that answer).
You only need such a simple invocation of find
for very old versions of bash
(pre-4.0). Using the globstar
operator is much simpler:
shopt -s globstar
for f in **/*.html; do
...
done