Herbert Xu
Thu, 12 Aug 2010 18:15:47 -0700
Eric Blake <ebl...@redhat.com> wrote:
>
> Generally not possible using only POSIX constructs (bash's 'set -o
> pipefail' and '${pipestat...@]}' are extensions). But what you _can_ do
> is play with exec to be able to propagate non-zero status from a
> particular portion of a pipeline through a temporary variable or file:
>
> $ exec 3>&1 # duplicate original stdout
> $ result=$(
> exec 4>&1 >&3 3>&- # move cmd subst stdout, and restore original
> { ./main.sh; echo $? >&4 # run command, and record its status
> } | head -n 3)
> $ echo $? # status from head
> $ echo $result # status from ./main.sh
> $ exec 3>&-
Another way is to use fifos. Cheers, -- Email: Herbert Xu <herb...@gondor.apana.org.au> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html