I have a script that uses find
to search for files and loops over the result for further processing.
for file in $(find ~ -type f -size +1G); do
filename=$(basename $file)
echo $file
done
When I run the find
command directly, it outputs matches directly. But its whin this script, the loop
first waits for the find
command to completely finish and afterwards loops over the result.
Is it possible to have the loop run over a match as soon as the find
command finds any match?
It would be possible with using pipe
the output, but I want to do more complex stuff in the loop afterwards than simple one line stuff.
for
loop will not start until its arg list is complete. You could change the construct tofind ... | while IFS='' read -r FN; do
but this can bring its own issues. If (as suggested) you can integrate the processing into-exec
or| xargs
, it would be more stable. – Paul_Pedant Dec 05 '20 at 20:10