From owner-freebsd-bugs@FreeBSD.ORG Fri Apr 3 19:40:05 2009 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A38FC1065676 for ; Fri, 3 Apr 2009 19:40:05 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 3BC468FC21 for ; Fri, 3 Apr 2009 19:40:05 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id n33Je4Y2098758 for ; Fri, 3 Apr 2009 19:40:04 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id n33Je4Gx098757; Fri, 3 Apr 2009 19:40:04 GMT (envelope-from gnats) Date: Fri, 3 Apr 2009 19:40:04 GMT Message-Id: <200904031940.n33Je4Gx098757@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Jilles Tjoelker Cc: Subject: Re: bin/34811: sh(1) "jobs" is not pipeable X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Jilles Tjoelker List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Apr 2009 19:40:06 -0000 The following reply was made to PR bin/34811; it has been noted by GNATS. From: Jilles Tjoelker To: bug-followup@FreeBSD.org, slaven.rezic@berlin.de, Martin.Kaeske@stud.tu-ilmenau.de, kerochan2@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