I have a bash script that look out for files recursively under multi-sub folders, then use ffmpeg to each file. at debug, it works great if i use echo ffmpeg but the thing is, at real work where it actually needs to use ffmpeg and wait for half an hour to finish for each video, the bash script cannot successfully run the ffmpeg to each fileMy snippet is below:find * \( -name '*.mkv' -o -name '*avi' -o -name '*mp4' -o -name '*flv' -o -name '*ogg' -o -name '*mov' ! -name '*-[900p-by-ZiriusPH].mkv' \) -print |while IFS= read file    ## IFS= prevents read stripping whitespacedo    ffmpeg -i $file $target && rm -rf $filedonethe thing is, because ffmpeg takes too long to respond, and while would just keep listing and executing. So I'm hoping what can I do to make sure loop would be process only after the done has ended?Can somebody please help? Thanks!Geez, I do not know why it was tagged as possible duplicate with another question of mine: Converting `for file in` to `find` so that my script can apply recursivelyI am asking for a loop action that would allow my bash script to wait for each function inside the loop to finish before iterating to the next object. It is very far from asking how to find files recursively. Thanks!
replace `while` with more suitable function so looping would wait for each process to end
centos;process;ffmpeg
Instead of piping find into the loop, you could go through anintermediate file. That will ensure that the finding step and thelooping step happen in sequence, with no overlap. Something like thefollowing (I altered your expression for brevity):find \( -name '*.mkv' -o -name '*avi' \) >files<files while IFS= read filedo    ffmpeg -i $file $target && rm -f $filedoneNote that this still isn't completely safe; using find -exec would be simpler if your requirements didn't include running find strictly before the first call to ffmpeg. With this requirement, using find -print0 along with xargs or GNU parallel could do the job.