jobs control in a /bin/sh script

Polytropon freebsd at edvax.de
Sun Jul 10 15:57:43 UTC 2016


On Sun, 10 Jul 2016 18:34:40 +0300, Nikos Vassiliadis wrote:
> Hi,
> 
> Is there a way to redirect "jobs" output?
> While this works on other bourne-like shells like zsh
> or bash, it doesn't on /bin/sh.
> 
> > $ sleep 100 &
> > $ sleep 100 &
> > $ jobs -p
> > 1760
> > 1761
> > $ jobs -p | cat
> > $
> 
> My code looks like this:
> > for j in $jobs
> > do
> >   (
> > 	blah; blah; blah;
> >   ) &
> > done
> 
> and I'd like to limit the number of jobs my script could create.

How about this?

JOBS=`jobs -p`
for j in $JOBS; do
	# ... whatever you need to do with $j ...
done

Or the iteration just shortened:

for j in `jobs -p`; do
	# ... whatever you need to do with $j ...
done




-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...


More information about the freebsd-questions mailing list