Re: Piping jobs output

From: Ron Wills <ron_at_digitalcombine.ca>
Date: Thu, 13 Jan 2022 15:07:40 UTC
On Wed, Jan 12, 2022 at 04:28:43PM -0500, Vlad Markov wrote:
> 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.
> > 
> Why not just install bash from the ports collection?
> 

This is what I have done for the time being but I do find this to
be rather strange behaviour from sh. Maybe this isn't the mailing
list for this but this test script demonstrates the problem.

for ITEM in 1 2 3 4 5 6 7 8 9; do
  echo "JOB: $ITEM"

  # Limit it to three jobs
  while [ "$(jobs | wc -l)" -ge 3 ]; do
    sleep 2
  done

  # Show jobs stats
  jobs
  echo " number of jobs = $(jobs | wc -l)"
  jobs | cat

  sleep 5 &
done

With bash only 3 jobs will run at a time. With sh it runs all 9
jobs without hesitation. After doing some further testing it seems
that jobs is the only builtin command that I can't pipe the 
output of.

-- 
Ron Wills
https://www.digitalcombine.ca
 Open Source & The Command Line