I'm trying to show thumbnails from youtube for specific timeout to user and then show next one I made this command:

while read line; do\
      wget -O- -q "$line" | \
      timeout 10s display ;\
done < <(youtube-dl --get-thumbnail https://www.youtube.com/watch?v=jPBdQRkWvGY https://www.youtube.com/watch?v=ybLXm5LOSks https://www.youtube.com/watch?v=9fr3ECCSo6U https://www.youtube.com/watch?v=EKST1uliDU8 )

But the images are shown for random time (some 10s and some 1s !!)

Does anyone have any idea what is them problem?


A shell pipeline executes the programs of the pipeline not one after another, but more or less at the exact same time (less so as the system becomes increasingly busy) as is shown by when the first three following date calls execute:

$ date +%s; (date +%s >&2; sleep 3) | (date +%s >&2; sleep 5); date +%s

Therefore the timeout timer is already counting down while wget is busy downloading the data but before display has had a chance to display said data.

One workaround would be to download the data in advance so that there is a list of files for display to work on; this would remove the delays caused by wget from the display portion.

for f in a_glob_that_matches_the_files_here; do
    timeout 10s display "$f"

I guess that the problem is that you and timeout see different starting points:

For you the timeout should begin when the image is displayed. But for timeout it begins when it is started.

There is a "random" gap between these two points in time: the download time. You must delay the execution of timeout until the download is finished.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.