Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 10 Jul 2016 17:52:19 +0200
From:      Polytropon <freebsd@edvax.de>
To:        Nikos Vassiliadis <nvass@gmx.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: jobs control in a /bin/sh script
Message-ID:  <20160710175219.48ef1d1a.freebsd@edvax.de>
In-Reply-To: <930cbcd1-2345-8a55-1b87-1691f5aa09a1@gmx.com>
References:  <930cbcd1-2345-8a55-1b87-1691f5aa09a1@gmx.com>

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



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