From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29878 invoked from network); 16 Aug 2004 01:06:21 -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 01:06:21 -0000 Received: (qmail 14140 invoked from network); 16 Aug 2004 01:06:14 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 16 Aug 2004 01:06:14 -0000 Received: (qmail 21569 invoked by alias); 16 Aug 2004 01:05:31 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7854 Received: (qmail 21559 invoked from network); 16 Aug 2004 01:05:30 -0000 Received: from unknown (HELO a.mx.sunsite.dk) (130.225.247.88) by 130.225.247.90 with SMTP; 16 Aug 2004 01:05:30 -0000 Received: (qmail 10802 invoked from network); 16 Aug 2004 01:04:16 -0000 Received: from erouter0.it-datacntr.louisville.edu (136.165.5.194) by a.mx.sunsite.dk with SMTP; 16 Aug 2004 01:04:14 -0000 Received: from [192.168.1.35] (tiger.slug.louisville.edu [136.165.47.43]) by erouter0.it-datacntr.louisville.edu (Postfix) with ESMTP id 074881587 for ; Sun, 15 Aug 2004 21:04:13 -0400 (EDT) Mime-Version: 1.0 (Apple Message framework v619) Content-Transfer-Encoding: 7bit Message-Id: <2FF1BBB1-EF20-11D8-9C9B-000A95EDC31A@louisville.edu> Content-Type: text/plain; charset=US-ASCII; format=flowed To: zsh-users@sunsite.dk From: Aaron Davies Subject: Slightly OT: Error-Handling in a Pipeline, preferably non-zsh Date: Sun, 15 Aug 2004 21:04:12 -0400 X-Mailer: Apple Mail (2.619) X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, hits=-0.4 required=6.0 tests=BAYES_20,FROM_ENDS_IN_NUMS autolearn=no version=2.63 X-Spam-Hits: -0.4 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 $@ but that doesn't work. Any ideas? (I could, of course, simply cache the last grep's results in a tmpfile, test its length, and proceed accordingly, but that doesn't seem quite as elegant. -- Aaron Davies agdavi01@louisville.edu