From owner-freebsd-questions@freebsd.org Sun Jul 10 15:57:43 2016 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 52BE3B83A48 for ; Sun, 10 Jul 2016 15:57:43 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx01.qsc.de (mx01.qsc.de [213.148.129.14]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 1F42F1AF2 for ; Sun, 10 Jul 2016 15:57:42 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from r56.edvax.de (port-92-195-96-167.dynamic.qsc.de [92.195.96.167]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx01.qsc.de (Postfix) with ESMTPS id 4E6523CDC0; Sun, 10 Jul 2016 17:52:20 +0200 (CEST) Received: from r56.edvax.de (localhost [127.0.0.1]) by r56.edvax.de (8.14.5/8.14.5) with SMTP id u6AFqJ1W004203; Sun, 10 Jul 2016 17:52:20 +0200 (CEST) (envelope-from freebsd@edvax.de) Date: Sun, 10 Jul 2016 17:52:19 +0200 From: Polytropon To: Nikos Vassiliadis 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> Reply-To: Polytropon Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Jul 2016 15:57:43 -0000 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, ...