bin/34811: sh(1) "jobs" is not pipeable
Jilles Tjoelker
jilles at stack.nl
Fri Apr 3 12:40:06 PDT 2009
The following reply was made to PR bin/34811; it has been noted by GNATS.
From: Jilles Tjoelker <jilles at stack.nl>
To: bug-followup at FreeBSD.org, slaven.rezic at berlin.de,
Martin.Kaeske at stud.tu-ilmenau.de, kerochan2 at gmail.com
Cc:
Subject: Re: bin/34811: sh(1) "jobs" is not pipeable
Date: Fri, 3 Apr 2009 21:34:18 +0200
The way I read POSIX, I think this does not have to work. Commands in a
pipeline with two or more commands may or may not be executed in a
subshell (this 'or' applies to each of the commands individually), and a
subshell has its own list of unwaited jobs.
Accordingly, (jobs) gives empty output (in /bin/sh as well as bash4).
bash4 seems to do special trickery with the jobs command in pipelines
(as permitted): even in commands like jobs >`tty` | jobs both give
proper output. This, however, breaks down if you make it more
complicated such as by replacing jobs with { jobs; }.
On the other hand, $(jobs) works in both /bin/sh and bash4, although
POSIX says that command substitution happens in a subshell. However,
POSIX also mentions $(jobs -p) in an informative section, and it seems
useful.
If you want to add this feature, evalpipe() in eval.c would probably be
the place. It would be quite specific to very few builtin commands which
tend not to be used much in scripts. (Note that slow operations in the
main shell process cannot be ^Z'ed, and that builtin commands may be
overridden with functions.)
--
Jilles Tjoelker
More information about the freebsd-bugs
mailing list