Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 14 Feb 2012 11:30:28 -0800
From:      Devin Teske <devin.teske@fisglobal.com>
To:        "'Matthew Story'" <matthewstory@gmail.com>, <freebsd-hackers@freebsd.org>
Subject:   RE: xargs short-circuit
Message-ID:  <094101cceb4f$1c79cd70$556d6850$@fisglobal.com>
In-Reply-To: <CAB%2B9ogd3owBKb0iGnaX3S=e1V%2BUvno2jGVnUShxXmehHOjjdsg@mail.gmail.com>
References:  <CAB%2B9ogcT3OxMKwTY%2B8KfzJfcBiHRBnSdSxcy2eYR6bn=uoL1UQ@mail.gmail.com>	<093b01cceb4b$9a956ba0$cfc042e0$@fisglobal.com> <CAB%2B9ogd3owBKb0iGnaX3S=e1V%2BUvno2jGVnUShxXmehHOjjdsg@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help


> -----Original Message-----
> From: owner-freebsd-hackers@freebsd.org [mailto:owner-freebsd-
> hackers@freebsd.org] On Behalf Of Matthew Story
> Sent: Tuesday, February 14, 2012 11:18 AM
> To: freebsd-hackers@freebsd.org
> Subject: Re: xargs short-circuit
> 
> On Tue, Feb 14, 2012 at 2:05 PM, Devin Teske
> <devin.teske@fisglobal.com>wrote:
> 
> >
> >
> > > -----Original Message-----
> > > From: owner-freebsd-hackers@freebsd.org [mailto:owner-freebsd-
> > > hackers@freebsd.org] On Behalf Of Matthew Story
> > > Sent: Tuesday, February 14, 2012 10:35 AM
> > > To: freebsd-hackers@freebsd.org
> > > Subject: xargs short-circuit
> > >
> > > After reading the man-page, and browsing around the internet for a
> > minute,
> > > I was just wondering if there is an option in (any) xargs to
> > short-circuit
> > > on first failure of [utility [arguments]].
> > >
> > > e.g.
> > >
> > > $ jot - 1 10 | xargs -e -n1 sh -c 'echo "$*"; echo exit 1' worker ||
> > echo $?
> > > 1
> > > 1
> > >
> > > such that any non-0 exit code in a child process would cause xargs to
> > stop
> > > processing.  seems like this would be a nice feature to have.
> > >
> >
> > You can achieve this quite easily with a sub-shell:
> >
> > As a bourne-shell script:
> >
> > #!/bin/sh
> > jot - 1 10 | ( while read ARG1 REST; do
> >        sh -c 'echo "$*"; exit 1' worker $ARG1 || exit $?
> >        shift 1
> > done )
> >
> 
> read is often not sufficient for a variety of reasons, the most notable of
> them is that new-lines are valid in file names on most file systems.

Your original example/post neither requested nor implied that such functionality
was required.

If you need such functionality, then you should be using awk, perl, or some
other heavier-lifting code (can even be sh(1), but you'll sacrifice speed).
-- 	
Devin

_____________
The information contained in this message is proprietary and/or confidential. If you are not the intended recipient, please: (i) delete the message and all copies; (ii) do not disclose, distribute or use the message in any manner; and (iii) notify the sender immediately. In addition, please be aware that any message addressed to our domain is subject to archiving and review by persons other than the intended recipient. Thank you.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?094101cceb4f$1c79cd70$556d6850$>