View Issue Details

IDProjectCategoryView StatusLast Update
00019801003.1(2024)/Issue8Shell and Utilitiespublic2026-04-26 07:45
Reporterstephane Assigned To 
PrioritynormalSeverityObjectionTypeEnhancement Request
Status NewResolutionOpen 
NameStephane Chazelas
Organization
User Reference
Sectionjobs utility
Page Number3021, 3023
Line Number101088-101091, 101194
Interp Status
Final Accepted Text
Summary0001980: misleading reference to $(jobs -p) in jobs application usage
DescriptionIn the "APPLICATION USAGE" section, the jobs utility
specification currently has:

> Usage such as $(jobs -p) provides a way of referring to the
> process group of the job in an implementation-independent way.

However, $(...) instroduces a subshell environment and the
"DESCRIPTION" section has:

> If the current shell execution environment (see 2.13 Shell
> Execution Environment) is not a subshell environment, the jobs
> utility shall display the status of background jobs that were
> created in the current shell execution environment; it may
> also do so if the current shell execution environment is a
> subshell environment.

Meaning the expansion of $(jobs -p) is unspecified.

What "so" means above in "it may also do so" should be clarified
as it's unclear whether it may report jobs of the shell outside
subshell environments, or jobs of the subshell environment or of
the parent subshell environment or combinations thereof.

In practice, there's a lot of variation between shells and in
some shells, not all subshells are equal, with the ones created
by command substitution treated differently from some other ones
in some for instance.

With bash:

$ bash -c 'sleep 1 & (sleep 2 & (sleep 3 & jobs))'
[1]+  Running                    sleep 3 &
$ bash -c 'sleep 1 & (sleep 2 & printf "%s\n" "$(sleep 3 & jobs)")'
[1]-  Running                    sleep 2 &
[2]+  Running                    sleep 3 &


Similarly for subshells incurred by pipelines:

$ bash -c 'sleep 1 & (jobs)'
$ bash -c 'sleep 1 & jobs | cat'
[1]+  Running                    sleep 1 &

Desired ActionIn the "APPLICATION USAGE" section, Remove the sentence:

> Usage such as $(jobs -p) provides a way of referring to the
> process group of the job in an implementation-independent way.

Or change it to:

> It provides a way of referring to the process group of a job
> in an implementation-independent way.

In the "DESCRIPTION" section, change:

> it may also do so if the current shell execution environment
> is a subshell environment.

To:

> If invoked in a subshell environment, whether it reports jobs of
> the current (subshell) execution environment, of the parent
> execution environment, or those outside any subshell
> environment or combinations thereof and under what circumstance
> is implementation-defined.

Or leave the whole thing unspecified:

> If invoked in a subshell environment, the behaviour is
> unspecified.

It's marked with the "User Portability Utilities" option anyway so
shouldn't be used in POSIX scripts.
TagsNo tags attached.

Issue History

Date Modified Username Field Change
2026-04-26 07:37 stephane New Issue
2026-04-26 07:45 stephane Note Added: 0007425