Re: Basic Bash Script Question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



2011/2/21 James Bensley <jwbensley@xxxxxxxxx>:

> I'm stuck trying to work this one out and my Google skills are
> apparently lacking today.
>
> This is a test bash script;
>
> #!/bin/bash
>
> do something | tee a.log
>
> if [ $? -ne 0]; then
>  echo broken
> fi
>
> The problem with this script is $? contains the exit value of the tee
> command, but I want to check the exit value of whatever command I put
> in place of 'do something'.
>
> How can I achieve this without loosing the tee operation, as 'do
> something' maybe a long running command with a lot of output like
> rsync?
>
> I don't want to;
> result=`do something`
> if [ $? -ne 0...
> ....
> fi
> echo $result

man bash

search for Pipelines, pipefail and PIPESTATUS.

--
Pascal
_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos



[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux