From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28103 invoked from network); 16 Aug 2004 03:06:00 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 16 Aug 2004 03:06:00 -0000 Received: (qmail 91457 invoked from network); 16 Aug 2004 03:05:55 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 16 Aug 2004 03:05:55 -0000 Received: (qmail 8238 invoked by alias); 16 Aug 2004 03:05:09 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7856 Received: (qmail 8228 invoked from network); 16 Aug 2004 03:05:08 -0000 Received: from unknown (HELO a.mx.sunsite.dk) (130.225.247.88) by 130.225.247.90 with SMTP; 16 Aug 2004 03:05:08 -0000 Received: (qmail 88947 invoked from network); 16 Aug 2004 03:03:37 -0000 Received: from tantale.fifi.org (216.27.190.146) by a.mx.sunsite.dk with SMTP; 16 Aug 2004 03:03:34 -0000 Received: from ceramic.fifi.org (mail@ceramic.fifi.org [216.27.190.147]) by tantale.fifi.org (8.9.3p2/8.9.3/Debian 8.9.3-21) with ESMTP id UAA23711; Sun, 15 Aug 2004 20:03:31 -0700 Received: from phil by ceramic.fifi.org with local (Exim 4.22) id 1BwXmU-0002MR-Iy; Sun, 15 Aug 2004 20:03:30 -0700 To: Aaron Davies Cc: zsh-users@sunsite.dk Subject: Re: Slightly OT: Error-Handling in a Pipeline, preferably non-zsh References: <2FF1BBB1-EF20-11D8-9C9B-000A95EDC31A@louisville.edu> Mail-Copies-To: nobody From: Philippe Troin Date: 15 Aug 2004 20:03:30 -0700 In-Reply-To: <2FF1BBB1-EF20-11D8-9C9B-000A95EDC31A@louisville.edu> Message-ID: <87n00v4we5.fsf@ceramic.fifi.org> User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: Philippe Troin X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, hits=-0.0 required=6.0 tests=BAYES_44 autolearn=no version=2.63 X-Spam-Hits: -0.0 Aaron Davies writes: > How do I do return-value error handling in the middle of a pipeline? > I'd ideally like to keep this to as basic a shell level as possible, > plain (Bourne) sh-compatible if it can be done, though a bash or zsh > solution will be fine if not. I'm tring to write a simple script that > will apply a command to all processes matching a name--sort of a > generalized "killall". At the moment, it looks like this: > > #!/bin/sh > > name=$1 > shift > > ps aux | grep $name | grep -v grep | grep -v $0 | awk '{ print $2 }' | > xargs $@ > > and it works fine, and I'd like to keep it at that level of > simplicity. The only thing is, I'd like to make it stop and return 1 > if there are no matching processes. (At the moment, it calls the > command with an empty argument list.) The intuitive thing to do seems > to be > > ps aux | grep $name | grep -v grep | ( grep -v $0 || exit 1 ) | awk '{ > print $2 }' | xargs $@ Use your first idiom and check $pipestatus[4]. Phil.