Search code examples
bashio-redirection

Why does redirection + pipe ( 2>&1 |) merge both streams instead of moving stderr to stdout?


I read that redirections are processed left to right. So in this example

 command 2>&1 | less

One would think that fd 2 is directed to fd 1 first and then fd 1 is sent to pipe. So fd 1 and 2 point to separate places.

But actually here fd 1 and 2 both point to the pipe, because for some reason fd 1 is sent to pipe first and then fd 2 is sent to fd 1. Why are redirections processed right to left in this case?


Solution

  • The pipe is not a redirection, so in fact redirections (of which there is only one in your example) are being processed the way you think. The pipe is a separate thing at the end.