- Subject: How to inherent non-zero exit status using pipe? (dash)
- From: Peng Yu <pengyu.ut@xxxxxxxxx>
- Date: Wed, 11 Aug 2010 07:34:43 -0500
Hi,
The following example returns the exit status of the last command in a
pipe. I'm wondering if there is a way to inherent non-zero exit status
using pipe. That is, if there is any command in a pipe that return a
non-zero status, I'd like the whole pipe return a non-zero status.
$ cat main.sh
#!/usr/bin/env bash
echo abc 1>&2
echo abc 1>&2
echo abc 1>&2
echo abc 1>&2
echo abc 1>&2
exit 1
$ ./main.sh
abc
abc
abc
abc
abc
$ echo $?
1
$ ./main.sh |head -n 3
abc
abc
abc
abc
abc
$ echo $?
0
--
Regards,
Peng
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
[LARTC]
[Bugtraq]
[Yosemite Forum]
[Photo]