I have a generator of files running, where each file has a name alphabetically following the previous one. At first I was doing my loop like
for file in /path/to/files*; do..., but I soon realized that the glob will only expand before the loop, and any new files created while looping won't be processed.
My current way of doing this is quite ugly:
while :; do doneFileCount=$(wc -l < /tmp/results.csv) i=0 for file in *; do if [[ $((doneFileCount>i)) = 1 ]]; then i=$((i+1)) continue else process-file "$file" # prints single line to stdout i=$((i+1)) fi done | tee -a /tmp/results.csv done
Is there any simple way to loop over ever-increasing list of files, without the hack described above?