The wait built-in waits for jobs to terminate.
Syntax
-
wait [job…]
Description
The wait built-in waits for background jobs to terminate. If job control is enabled, stopped jobs are considered as terminated.
The built-in can be used to wait for asynchronous commands if job control is disabled.
If the shell receives a signal while the built-in is waiting and if a trap has been set for the signal, then the trap is executed and the built-in immediately finishes (without waiting for the jobs). If the shell receives a SIGINT signal when job control is enabled, the built-in aborts waiting.
If the shell is interactive, job-controlling, and not in the POSIXly-correct mode, the job status is printed when the job is terminated or stopped.
Operands
- job
-
The job ID of the job or the process ID of a process in the job.
If no jobs are specified, the built-in waits for all existing jobs.
If the specified job does not exist, the job is considered to have terminated with the exit status of 127.
Exit status
If no jobs were specified and the built-in successfully waited for all the jobs, the exit status is zero. If one or more jobs were specified, the exit status is that of the last job.
If the built-in was aborted by a signal, the exit status is an integer (> 128) that denotes the signal. If there was any other error, the exit status is between 1 and 126 (inclusive).
Notes
The wait built-in is a mandatory built-in.
The process ID of the last process of a job can be obtained by the
!
special parameter.
You can use the jobs built-in as well to obtain process IDs
of job processes.