3 ms·
To be even more pedantic, you actually want to do while read -d '' fname do echo "fname: $fname" done <<<"$(find . -type f -print0)" Because
by cyphar 6y ago
To be even more pedantic, you actually want to do
while read -d '' fname
do
echo "fname: $fname"
done <<<"$(find . -type f -print0)"
Because if you wanted to export a variable from the loop body, it wouldn't work in your example -- the loop is running in a subshell when you pipe output into it. <<<"$(...)" is not exactly the same thing (it doesn't stream input) but it does allow you to get around this problem. For folks who suggested glob expansion -- that's okay for simple file listings, but find lets you do more complicated ones that can be quite useful. Not to mention that the suggested
for fname in *; ...
Is not actually doing the same thing -- find lists files recursively.