You're viewing a comment by AltairIV and its responses.

AltairIV Permalink
January 14, 2013, 12:32

It's a bit late, but to address Alan's behavior:

As always, the redirections are being set up in order from left to right, and the sub-processes are inheriting the file descriptors from the parent.

The first, stdout, redirection gets set to the anonymous pipe created by the process substitution (e.g. /dev/fd/60), as expected. And the sed command inside it uses that as its stdin (and its stdout/stderr go to the terminal).

But when the second, stderr, process substitution is set up, the sed command inside it inherits the redirected stdout of the parent. This means it's using 1>/dev/fd/60, and its output is getting redirected right back into the first sed!

So the secret is simply to reverse the file descriptors so that stderr is defined before stdout.

$ ls one.txt two.txt 2> >(sed "s/^/E /") > >(sed "s/^/O /")
O one.txt
E ls: cannot access two.txt: No such file or directory

Or alternately to re-redefine it, as raphael did.

Reply To This Comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "sandbox_329": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.