View Issue Details

IDProjectCategoryView StatusLast Update
00019801003.1(2024)/Issue8Shell and Utilitiespublic2026-05-21 16:09
Reporterstephane Assigned Tolanodan  
PrioritynormalSeverityObjectionTypeEnhancement Request
Status ResolvedResolutionAccepted As Marked 
NameStephane Chazelas
Organization
User Reference
Sectionjobs utility
Page Number3021, 3023
Line Number101088-101091, 101194
Interp Status---
Final Accepted Text 0001980:0007431
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.
Tagstc1-2024

Activities

stephane

2026-04-26 07:45

reporter   bugnote:0007425

For context, it came up at this Q&A: https://unix.stackexchange.com/questions/672384/cant-grep-or-word-count-the-output-of-jobs-command-in-dash

lanodan

2026-05-21 16:05

manager   bugnote:0007431

Proposed change
On lines 101194-101195, page 3023, of section jobs:
Usage such as $(jobs −p) provides a way of referring to the process group of the job in an
implementation-independent way.

to
Usage such as jobs −p >tempfile provides a way of referring to the process group of the job in an
implementation-independent way. Note that $(jobs -p) runs jobs in a subshell, and may not be portable.

Issue History

Date Modified Username Field Change
2026-04-26 07:37 stephane New Issue
2026-04-26 07:45 stephane Note Added: 0007425
2026-05-21 16:05 lanodan Note Added: 0007431
2026-05-21 16:07 lanodan Assigned To => lanodan
2026-05-21 16:07 lanodan Status New => Resolved
2026-05-21 16:07 lanodan Resolution Open => Accepted As Marked
2026-05-21 16:07 lanodan Interp Status => ---
2026-05-21 16:08 lanodan Tag Attached: tc1-2024
2026-05-21 16:09 lanodan Final Accepted Text => 0001980:0007431