On Mon, Apr 27, 2009 at 05:02:26PM +0300, Angel Tsankov wrote:
> I'd like to pipe the output from a command, say A, to another command, say 
> B, then check if both commands completed successfully (i.e.with exist status 
> 0)

       PIPESTATUS
              An array variable (see Arrays below) containing a list  of  exit
              status  values  from the processes in the most-recently-executed
              foreground pipeline (which may contain only a single command).

> and, if so, compare the standard output from command B to some string. 
> How can I do this in a bash script?

Ah, that makes it much trickier.  You can't use PIPESTATUS when you're
capturing the output of a pipeline with a command substitution.

arc1:~$ x() { echo x; exit 1; }
arc1:~$ y() { echo y; exit 0; }
arc1:~$ x|y; echo "${pipestat...@]}"
y
1 0
arc1:~$ q=$(x|y); echo "${pipestat...@]}"
0

In this case, you will need either a temporary file, or a named pipe.


Reply via email to