All of lore.kernel.org
 help / color / mirror / Atom feed
* How to inherent non-zero exit status using pipe? (dash)
@ 2010-08-11 12:34 Peng Yu
  2010-08-11 13:51 ` Eric Blake
  0 siblings, 1 reply; 3+ messages in thread
From: Peng Yu @ 2010-08-11 12:34 UTC (permalink / raw)
  To: dash

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-08-13  1:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-11 12:34 How to inherent non-zero exit status using pipe? (dash) Peng Yu
2010-08-11 13:51 ` Eric Blake
2010-08-13  1:15   ` Herbert Xu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.