Remix.run Logo
kazinator 4 hours ago

The point is that the order in which that is processed is not left to right.

First the | pipe is established as fd [1]. And then 2>&1 duplicates that pipe into [2]. I.e. right to left: opposite to left-to-right processing of redirections.

When you need to capture both standard error and standard output to a file, you must have them in this order:

  bob > file 2>&1
It cannot be:

  bob 2>&1 > file
Because then the 2>&1 redirection is performed first (and usually does nothing because stderr and stdout are already the same, pointing to your terminal). Then > file redirects only stdout.

But if you change > file to | process, then it's fine! process gets the combined error and regular output.