bug-bash
[Top][All Lists]
Advanced

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

Re: 'foo > >(bar)' doesn't set $! for external foo not invoked via 'comm


From: Rusty Bird
Subject: Re: 'foo > >(bar)' doesn't set $! for external foo not invoked via 'command'
Date: Mon, 20 Jul 2020 10:21:36 +0000

Oğuz:
> > For context - I'm filtering a program's stdout and stderr
> > (separately), requiring successful exit statuses for the program and
> > both filters:
> >
> >         set -u -o pipefail
> >         { program 2> >(stderr_filter >&2) && wait $!; } | stdout_filter &&
> > ...

> Not sure if process substitution is really necessary here,
> 
>     set -u -o pipefail
>     { program 2>&3 | stdout_filter;  } 3>&1 | stderr_filter && ...
> 
> does the same thing.

That one filters program's stdout twice - first through stdout_filter
and then through stderr_filter - with program's stdout and stderr both
finally arriving at stdout. But tweaked like this, it seems to cover
all the bases:

        set -u -o pipefail
        {
            program 2>&1  >&"$out" {out}>&- |
            stderr_filter >&2      {out}>&-
        } {out}>&1 | stdout_filter

And it even waits for stderr_filter if program failed. My original
snippet neglected that case, otherwise it would have looked more like

       set -u -o pipefail
       (
           trap 'wait $! || exit $?' EXIT
           command program 2> >(stderr_filter >&2)
       ) | stdout_filter

which isn't exactly pretty either, even if the bug(?) requiring
'command' is fixed.

Rusty

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]