Re: Piping jobs output

From: Vlad Markov <dvoich_at_optonline.net>
Date: Wed, 12 Jan 2022 21:28:43 UTC
On Wed, 12 Jan 2022 14:02:50 -0600
Ron Wills <ron@digitalcombine.ca> wrote:

> 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.
> 
Why not just install bash from the ports collection?