wait — wait for a child task in Bash
cheat sheet · Ubuntu 24.04; Bash 5.2 for shell builtins https://lab.dimsanych.ru/en/wiki/wait/Cheat sheet
-
type waitconfirm that this is a builtin -
help waitcurrent Bash help -
sleep 2 &create a short child task -
child_pid=$!save its PID in this shell -
wait "$child_pid"wait for its result -
printf '%s\n' "$?"immediately display wait status
Options
Bash 5.2 supports waiting for a PID or job, -n for the next completed
eligible child, and -p to save the selected identifier together with -n.
With job control enabled, -f requires termination rather than merely a state
change.
Without operands, the command waits for the shell's background tasks and
returns zero. That is not an aggregate guarantee that every task succeeded:
collect individual statuses for that. Use help wait for the installed
version's details.