Detecting errors in a pipe in ash
Denys Vlasenko
vda.linux at googlemail.com
Fri Dec 4 22:05:12 UTC 2009
On Friday 04 December 2009 12:37, Michael Abbott wrote:
> On Fri, 4 Dec 2009, Michael Abbott wrote:
>
> > When running the command:
> > command1 | command2
> > is there any way to detect in ash that command1 has failed?
> > Unfortunately the default return code is set to that of the last command
> > in the pipe, command2 in this case.
> >
> > In bash I can run
> > set -o pipefail
> > which sets the error code to that of the last non-zero status in the
> > pipe, which is normally precisely what it wanted. Alternatively, of
> > course, I can always interrogate $PIPESTATUS.
> >
> > Unfortunately ash understands neither of these constructs. Is there a
> > third workaround, or do I need to figure out how to hack ash?
> > Fortunately it looks as if `set -o` is already implemented, so I may be
> > in luck...
>
> Well, looking more closely at ash it's clear that the only solution is to
> implement this function. Fortunately (unless I've missed something,
> likely enough, there's a lot of code there) it seems easier than I feared:
Applied, thanks!
I edited it a bit and made conditional on ASH_BASH_COMPAT.
Try current git.
--
vda
More information about the busybox
mailing list