Paul Wagner <paul_s...@posteo.net> writes: > Now I tried > > { i=1; while [[ $i != 100 ]]; do echo > "http://domain.com/path/segment_$((i++)).mp4"; done } | wget -O foo.mp4 > -i - > > which works like a charm *as long as the 'generator process' is finite*, > i.e. the loop is actually programmed as in the example. The problem is > that it would be much easier if I could let the loop run forever, let > wget get whatever is there and then fail after the counter extends to a > segment number not available anymore, which would in turn fail the whole > pipe.
Good God, this finally motivates me to learn about Bash coprocesses. I think the answer is something like this: coproc wget -O foo.mp4 -i - i=1 while true do rm -f foo.mp4 echo "http://domain.com/path/segment_$((i++)).mp4" >&$wget[1] sleep 5 # The only way to test for non-existence of the URL is whether the # output file exists. [[ ! -e foo.mp4 ]] && break # Do whatever you already do to wait for foo.mp4 to be completed and # then use it. done # Close wget's input. exec $wget[1]<&- # Wait for it to finish. wait $wget_pid Dale