Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 13 Jan 2022 09:07:40 -0600
From:      Ron Wills <ron@digitalcombine.ca>
To:        questions@freebsd.org
Subject:   Re: Piping jobs output
Message-ID:  <20220113150740.GA57053@digitalcombine.ca>
In-Reply-To: <20220112162843.6a383da1f31c934f0e96e45b@optonline.net>
References:  <Yd8z6haDopLrG2C7@digitalcombine.ca> <20220112162843.6a383da1f31c934f0e96e45b@optonline.net>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20220113150740.GA57053>