wait
In this page:
wait
wait pauses a script until a background job finishes, or until all background jobs finish if called with no arguments. wait $pid waits for one specific job and captures its exit status. This is essential for coordinating multiple background tasks before moving on.
Note: Call wait with no arguments to pause until *every* background job the script started has completed.
Example: wait
#!/bin/bash
sleep 1 &
sleep 1 &
echo "Waiting for all background jobs..."
wait
echo "All background jobs finished"
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 12 topics to unlock
0/12 topics done
Complete these topics first: