Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Slightly OT: Error-Handling in a Pipeline, preferably non-zsh
- X-seq: zsh-users 7856
- From: Philippe Troin <phil@xxxxxxxx>
- To: Aaron Davies <agdavi01@xxxxxxxxxxxxxx>
- Subject: Re: Slightly OT: Error-Handling in a Pipeline, preferably non-zsh
- Date: 15 Aug 2004 20:03:30 -0700
- Cc: zsh-users@xxxxxxxxxx
- In-reply-to: <2FF1BBB1-EF20-11D8-9C9B-000A95EDC31A@xxxxxxxxxxxxxx>
- Mail-copies-to: nobody
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <2FF1BBB1-EF20-11D8-9C9B-000A95EDC31A@xxxxxxxxxxxxxx>
- Sender: Philippe Troin <phil@xxxxxxxx>
Aaron Davies <agdavi01@xxxxxxxxxxxxxx> 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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author