builtin

wait -n

Wait for one eligible completion; returns its status, or 127 if no eligible child exists. Interrupted waits can return nonzero without a completion.

Formal Syntax & Structure

bash syntaxbash
wait -n [id ...]

Parameters & Attributes

NameTypeDescription
idPID or jobspecOptional eligible child identifiers.

Return Value

exit status

Wait for one eligible completion; returns its status, or 127 if no eligible child exists. Interrupted waits can return nonzero without a completion.

Working Example

Example Snippetbash
( sleep 0.3; exit 6 ) &pid=$!wait -n -p finished "$pid"rc=$?[[ $finished == "$pid" ]] || exit 1printf 'matched status=%s\n' "$rc"
Bash Reference