Doesn't the bash shell already run the commands one by one and wait for the executed command to finish? So when and why do we need the wait
command?
Bash Wait Command – When and Why It Is Needed
bashwait
bashwait
Doesn't the bash shell already run the commands one by one and wait for the executed command to finish? So when and why do we need the wait
command?
Best Answer
You use
wait
if you have launched tasks in background, e.g.In this example the script starts three background tasks. These will run concurrently in the background and the
wait
will wait for all three tasks to finish. Oncewait
returns, the script continues with processing theecho done
.As pointed out in comment
wait
can be given a job number (wait %3
) or a pid (wait 1234
). While it is easy ( usingjob
orps
) in interactive bash to find those, it might be more difficult in batch mode.