help-bash
[Top][All Lists]
Advanced

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

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


From: Peng Yu
Subject: Re: [Help-bash] stdout and stderr to two different process substitutions
Date: Wed, 25 Jan 2012 09:50:35 -0600

>> If I just call "tee yy", nothing will be printed to stdout. "STDERR"
>> comes from stdin. How come "1>&2" redirect stdin to stderr? Thanks!

To make my reply complete here, I just correct that "stdin" above
should be "stdout" to avoid any confusion.

> Second of all, "just calling tee yy" means it's waiting for you to type
> something.  If you type a line and press Enter, it will write a copy to
> stdout (the terminal), and another copy to the file yy.

When I say "just calling tee yy", I implicitly meant it should be
within the context (as the full command is too long to type, but it
obviously caused confusions). I.e., I mean the following command.

{ echo STDOUT ; echo STDERR 1>&2 ;} > >(gzip > xx.gz) 2> >(tee yy)

> I'll ignore the "STDERR comes from stdin" part, since that makes no sense.

"{ echo STDOUT ; echo STDERR 1>&2 ;}" output the string "STDERR" to
the stderr file handle. "2> >(...)" redirects it to the stdin to what
is inside '()', in this example, tee. So if you consider tee, the
string "STDERR" is piped to its stdin. Does it make sense now?

> 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?

So essentially, the main stderr is redirect to the stdin of tee, tee
output to its stdout (see Note) which is then redirected to to main
stderr so that I can see the string "STDERR" again in the terminal?

 $ { echo STDOUT ; echo STDERR 1>&2 ;} > >(gzip > xx.gz) 2> >(tee yy 1>&2)

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?

-- 
Regards,
Peng



reply via email to

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