From nobody Wed Jan 12 20:02:50 2022 X-Original-To: freebsd-questions@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 ABB241944831 for ; Wed, 12 Jan 2022 20:03:06 +0000 (UTC) (envelope-from ron@digitalcombine.ca) Received: from hadesmail.canspace.ca (hadesmail.canspace.ca [142.44.129.205]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4JYz5554Wpz3LYK for ; Wed, 12 Jan 2022 20:03:05 +0000 (UTC) (envelope-from ron@digitalcombine.ca) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=digitalcombine.ca; s=default; h=Content-Type:MIME-Version:Message-ID: Subject:To:From:Date:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=o0ctlvJeNUVL1TY5I9B06E/eXGNLyPExsDWoqACsfOk=; b=q2h8bTcCVlRFjIrP2r62M7TgXz 4iQQZRsJwOIa/UlfgxSAapiqigbY4klsnCNVcEmA1Y+g+mdCyqY+JU4AS7IN6dgSCWjrr3R6ZenrF zLZZ9RbzyeEdsfZYYuW4U/BuwZ8FxMEt4L/6x7By+KH2/GXYZ9RuLo1KlNR9lJIWQ0AQMTvsmiqhk y3zkkvWOMNCefFi2E6oTkD/4Im+bf0D9S4XxVoE8S/9cZFgFnx1pEGnmApNqI/ZxVg1VBCIt7Chz+ fZ6GhmXTEND4/fsQMB67Zrgs8iyeytBybArMMeZwKtEsGbsTfSjGUUuykAcfGYm0OP4RzVsundGQQ 3owT6Prg==; Received: from static24-89-71-182.r.rev.accesscomm.ca ([24.89.71.182]:28556 helo=digitalcombine.ca) by hades.canspace.ca with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n7jpe-00034w-BR for freebsd-questions@freebsd.org; Wed, 12 Jan 2022 15:02:58 -0500 Date: Wed, 12 Jan 2022 14:02:50 -0600 From: Ron Wills To: freebsd-questions@freebsd.org Subject: Piping jobs output Message-ID: Mail-Followup-To: freebsd-questions@freebsd.org List-Id: User questions List-Archive: https://lists.freebsd.org/archives/freebsd-questions List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-questions@freebsd.org X-BeenThere: freebsd-questions@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - hades.canspace.ca X-AntiAbuse: Original Domain - freebsd.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - digitalcombine.ca X-Get-Message-Sender-Via: hades.canspace.ca: authenticated_id: ron@digitalcombine.ca X-Authenticated-Sender: hades.canspace.ca: ron@digitalcombine.ca X-Source: X-Source-Args: X-Source-Dir: X-Rspamd-Queue-Id: 4JYz5554Wpz3LYK X-Spamd-Bar: --- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=digitalcombine.ca header.s=default header.b=q2h8bTcC; dmarc=none; spf=pass (mx1.freebsd.org: domain of ron@digitalcombine.ca designates 142.44.129.205 as permitted sender) smtp.mailfrom=ron@digitalcombine.ca X-Spamd-Result: default: False [-3.50 / 15.00]; RCVD_TLS_ALL(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[digitalcombine.ca:s=default]; MID_RHS_MATCH_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; HAS_X_SOURCE(0.00)[]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; NEURAL_HAM_LONG(-1.00)[-1.000]; DMARC_NA(0.00)[digitalcombine.ca]; R_SPF_ALLOW(-0.20)[+ip4:142.44.129.205]; DKIM_TRACE(0.00)[digitalcombine.ca:+]; NEURAL_HAM_SHORT(-1.00)[-0.995]; HAS_X_GMSV(0.00)[ron@digitalcombine.ca]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; HAS_X_ANTIABUSE(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:16276, ipnet:142.44.128.0/17, country:FR]; RCVD_COUNT_TWO(0.00)[2]; HAS_X_AS(0.00)[ron@digitalcombine.ca] X-ThisMailContainsUnwantedMimeParts: N I have a number of shell scripts that scan various directories updating files. They can be quite time consuming so I put parts of the operations in the background and use "jobs" to manage how many things I put in the background. With bash this work beautifully but with FreeBSD's /bin/sh it's broken. So here's how I've been doing things: How I count the number of jobs I have in the background: jobs | wc -l In my scanning loop, to limit the jobs I create I have: while [ "$(jobs | wc -l)" -ge 4 ]; do sleep 2 done In /bin/sh the piping of jobs output doesn't seem to work. This lists all the jobs: jobs This always returns 0: jobs | wc -l The just returns an empty line: jobs | cat I don't know if I've stumbled on a bug or feature. I haven't seen anything that says I can't pipe the output of builtin commands in sh. This is on the lastest version FreeBSD 13. -- Ron Wills https://www.digitalcombine.ca Open Source & The Command Line