Complete the code to run a command in the background.
sleep 10 [1]
Adding & at the end of a command runs it in the background, allowing the shell to continue without waiting.
Complete the code to wait for a background process to finish.
sleep 5 & [1]
The wait command pauses the script until all background jobs finish.
Fix the error in the code to correctly bring a background job to the foreground.
sleep 20 & [1]
The fg command brings a background job to the foreground. The number 1 refers to the job ID.
Fill both blanks to create a loop that runs a command and waits for it to finish before continuing.
for i in {1..3}; do sleep 2 [1] [2] echo "Done $i" done
Running sleep 2 & starts the sleep in the background, and wait pauses until it finishes before echoing.
Fill all three blanks to create a dictionary-like output of job IDs and their statuses.
jobs_output=$(jobs) while read -r line; do job_id=$(echo $line | awk [1]) status=$(echo $line | awk [2]) echo "Job $[3]: $status" done <<< "$jobs_output"
The first awk prints the job ID (first field), the second prints the status (second field), and the echo uses the job_id variable.