[Top][All Lists]

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

Re: [Help-bash] stdout and stderr to two different process substitutions

From: Chet Ramey
Subject: Re: [Help-bash] stdout and stderr to two different process substitutions
Date: Wed, 25 Jan 2012 14:47:53 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:8.0) Gecko/20111105 Thunderbird/8.0

On 1/25/12 11:04 AM, Greg Wooledge wrote:
> On Wed, Jan 25, 2012 at 09:50:35AM -0600, Peng Yu wrote:
>>> pipe A leads to gzip, whose stdout goes to the file xx.gz.  Special pipe
>>> B leads to tee, which writes a copy of the piped input to the file yy,
>>> and another copy of the piped input to the screen (foo's stderr).
>> This looks a little wired to me. I though that the last "2" refers to
>> the stderr of tee, but it actually refers to the stderr of the main
>> process?
> tee inherits stderr from the script, *before* the script's stderr is
> redirected to the special pipe.  So writing to tee's stderr is basically
> writing to the script's stderr before it gets modified.
>> Note: I'm a little confused whether it should be tee's stdout or the
>> main stdout. It seems to be tee's stdout, as I don't see any output
>> from
>>  { echo STDOUT ; echo STDERR 1>&2 ;} > >(gzip > xx.gz) 2> >(tee yy)
>> But this sees to be asymmetric, why tee's stdout is redirected to the
>> main stderr but not tee' stderr?
> First, let's observe what it actually does:
> imadev:~$ cat yy
> imadev:~$ zcat xx.gz 
> The only explanation which can account for that behavior is that the
> process substitutions are not all done at the same time.
>   foo > >(gzip) 2> >(tee)
>       ^  ^       ^  ^
>       |  |       |  |
>       2  1       4  3
> It appears that each process substitution is done immediately before its
> accompanying redirection.  In order 1 2 3 4 as shown in the diagram.

Of course.  Redirections are processed left to right (or, in the Posix
parlance, `beginning to end').  The process substitutions are part of
the redirection, and expanded when the redirection is performed.

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden

reply via email to

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