← Back to Bash Course | Chapter 10: Text Processing Tools | Lesson 4 of 12

wait

In this page:

  1. wait

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

bash
#!/bin/bash
sleep 1 &
sleep 1 &

echo "Waiting for all background jobs..."
wait
echo "All background jobs finished"
🔒

Chapter Quiz — Complete all 12 topics to unlock

0/12 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.