From nobody Tue Jan 18 23:33:34 2022 X-Original-To: bugs@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 1471D195248C for ; Tue, 18 Jan 2022 23:33:35 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JdlTB6WTQz3rnQ for ; Tue, 18 Jan 2022 23:33:34 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C0EFB244E for ; Tue, 18 Jan 2022 23:33:34 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 20INXYMB039587 for ; Tue, 18 Jan 2022 23:33:34 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 20INXYNl039586 for bugs@FreeBSD.org; Tue, 18 Jan 2022 23:33:34 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 261200] Unable to pipe the output of jobs in sh Date: Tue, 18 Jan 2022 23:33:34 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: bin X-Bugzilla-Version: 13.0-STABLE X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: jilles@FreeBSD.org X-Bugzilla-Status: Open X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated List-Id: Bug reports List-Archive: https://lists.freebsd.org/archives/freebsd-bugs List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-bugs@freebsd.org MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642548814; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kXbZaKbdgs9xS38oWqDEbFffVFBSvlvM6zN5Lx2Eu/U=; b=alb5zRsiwU5T2Ivtv/90x3x32Iv36s5fspHJLpxj4M1uQ7547leq6wBgCa8z4i8YaN6Www xtGsriH5hlRaiETbuKGGTsZoNa8DHUeFSYI0XwvziuL/A1bJXcolfd2y2XoS48ANkp3Cwx bP9omw4RUbBkUN6vuI81cocHoohZeIfCLfYAgtAOXJrGFnEgLu2xO6kPQZjgim2GTEm7sP waJUBo+kUvOE1pki4gOqbtMbd4BIrIjh+cFDZeT7VH+kcbkj5V12hQH1FhbqaoObbR5um9 IukB7lIekNpyyyD4/vaRCrKsyV/d6B6qu3w7Lgmb8rFMYyNnLNgSfec3ToJgfw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1642548814; a=rsa-sha256; cv=none; b=xkyqYUBIFu+KHHObFTqI4GWkJ0fbu1cUEO085+9BeIsZ9hCtVpj76jq76TopBqQwPZKonN 6jejyKKi7IjM3eOAWQ+ERvoEosZQrWagNYd6e3XlD5DbGTjcVnQkCswLtET8bI75yzbCYZ SJwArjI14NotxjGmAcPhEWIaRQ7FG7GJYSzsqkflVXZfE5q448MP0VkFvMLph1Jlg6wHIU LP+y/kOx3iUWtnONdJmYDOlLO1RbBT17muDeJaOZNMe+GI87UtKrVVS/RsiBFDs0YFxVn2 XHftDfA9RZfpz+ioCP543ZbhFGjRJEN2SxfKbMna7h4du0Ku9ZfKzLz5Au+DOQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D261200 --- Comment #6 from Jilles Tjoelker --- The reason that jobs cannot be piped is that an element of a pipeline (with more than one element) is run in a subshell environment, and the subshell environment has its own jobs. For example, sh -c ':& { :& jobs; }|wc -l' writes 1. There are, however, some exceptions to this. One such exception is that if a command substitution contains a single jobs command, this jobs command returns information about the parent shell environment. This exception is documented in the man page under "Command Substitution". The command is otherwise still executed in a subshell environment, so, for example, variable assignments in expansions do not persist. Technically, this is implemented by executing certain command substitutions in the same process; among other things, resetting the jobs t= able is skipped and anything that would alter it does not follow this code path. This exception is commonly available (like the one for `trap` which has an Austin Group interpretation: https://www.austingroupbugs.net/view.php?id=3D= 53 ), but is not always implemented the way FreeBSD sh implements it. Some other shells instead implement it by making `jobs` (or `trap`) return the informa= tion from just before the subshell environment was entered if no change had been made yet, but in the case of `jobs` this is a bit unfortunate: either it creates an observable difference between (non-special) builtins and external programs, or it requires trickery to ensure a foreground job can be run wit= hout disturbing the jobs table for display by `jobs`. In bash (5.1.16(0)-release), `:& jobs | wc -l` and `:& J=3Djobs; $J | wc -l` work, but `:& { jobs; } | wc -l` does not, so bash appears to use a similar analysis like FreeBSD sh uses for command substitutions. --=20 You are receiving this mail because: You are the assignee for the bug.=