From owner-freebsd-hackers@FreeBSD.ORG Tue Feb 14 19:30:25 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 305A91065675 for ; Tue, 14 Feb 2012 19:30:25 +0000 (UTC) (envelope-from Devin.Teske@fisglobal.com) Received: from mx1.fisglobal.com (mx1.fisglobal.com [199.200.24.190]) by mx1.freebsd.org (Postfix) with ESMTP id ECA198FC19 for ; Tue, 14 Feb 2012 19:30:24 +0000 (UTC) Received: from pps.filterd (ltcfislmsgpa02 [127.0.0.1]) by ltcfislmsgpa02.fnfis.com (8.14.4/8.14.4) with SMTP id q1EJQTH9012107; Tue, 14 Feb 2012 13:30:24 -0600 Received: from smtp.fisglobal.com ([10.132.206.16]) by ltcfislmsgpa02.fnfis.com with ESMTP id 12yw2fg801-2 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); Tue, 14 Feb 2012 13:30:24 -0600 Received: from dtwin (10.14.152.15) by smtp.fisglobal.com (10.132.206.16) with Microsoft SMTP Server (TLS) id 14.1.323.3; Tue, 14 Feb 2012 13:30:23 -0600 From: Devin Teske To: "'Matthew Story'" , References: <093b01cceb4b$9a956ba0$cfc042e0$@fisglobal.com> In-Reply-To: Date: Tue, 14 Feb 2012 11:30:28 -0800 Message-ID: <094101cceb4f$1c79cd70$556d6850$@fisglobal.com> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQME1IwY3hQgsGd4pWahiNSUT3uF7AJSTotAARbuYnOTsand8A== Content-Language: en-us X-Originating-IP: [10.14.152.15] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.6.7361, 1.0.260, 0.0.0000 definitions=2012-02-14_04:2012-02-14, 2012-02-14, 1970-01-01 signatures=0 Cc: Subject: RE: xargs short-circuit X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Feb 2012 19:30:25 -0000 > -----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 > 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.