A job may also be referred to using a prefix of the name used to start it, or using a substring that appears in its command line. For example, ‘%ce’ refers to a stopped ce job.
Using ‘%?ce’, on the other hand, refers to any job containing the string ‘ce’ in its command line. If the prefix or substring matches more than one job, Bash reports an error.
Simply naming a job can be used to bring it into the foreground: ‘%1’ is a synonym for
‘fg %1’, bringing job 1 from the background into the foreground. Similarly, ‘%1 &’ resumes job 1 in the background, equivalent to ‘bg %1’
The shell learns immediately whenever a job changes state. Normally, Bash waits until it is about to print a prompt before reporting changes in a job’s status so as to not interrupt any other output. If the -b option to the set builtin is enabled, Bash reports such changes immediately (see Section 4.3.1 [The Set Builtin], page 58). Any trap on SIGCHLD is executed for each child process that exits.
If an attempt to exit Bash is made while jobs are stopped, (or running, if the checkjobs option is enabled – see Section 4.3.2 [The Shopt Builtin], page 62), the shell prints a warning message, and if the checkjobs option is enabled, lists the jobs and their statuses. The jobs command may then be used to inspect their status. If a second attempt to exit is made without an intervening command, Bash does not print another warning, and any stopped jobs are terminated.
7.2 Job Control Builtins bg bg [jobspec ...]
Resume each suspended job jobspec in the background, as if it had been started with ‘&’. If jobspec is not supplied, the current job is used. The return status is zero unless it is run when job control is not enabled, or, when run with job control enabled, any jobspec was not found or specifies a job that was started without job control. fg fg [jobspec]
Resume the job jobspec in the foreground and make it the current job. If jobspec is not supplied, the current job is used. The return status is that of the command placed into the foreground, or non-zero if run when job control is disabled or, when run with job control enabled, jobspec does not specify a valid job or jobspec specifies a job that was started without job control. jobs jobs [-lnprs] [jobspec] jobs -x command [arguments]
The first form lists the active jobs. The options have the following meanings:
-l
List process ids in addition to the normal information.
-n
Display information only about jobs that have changed status since the user was last notified of their status.
-p
List only the process id of the job’s process group leader.