Re:Results of the Grand C++ Error Explosion Competition
by waynecochran on Sunday January 26, 2014 @09:58PM
(#7128463)
I actually have this written on the corner of my whiteboard because I can never remember bash's syntax for piping out stderr!
[ Parent
| on HN ]
Re:Results of the Grand C++ Error Explosion Competition
by JoshTriplett on Sunday January 26, 2014 @10:01PM
(#7128479)
If you don't mind being bash-specific, you can shorten 2>&1 | to just |& .
Re:Results of the Grand C++ Error Explosion Competition
by coherentpony on Sunday January 26, 2014 @10:40PM
(#7128645)
Good lord. I think you just changed my life.
Re:Results of the Grand C++ Error Explosion Competition
by praptak on Monday January 27, 2014 @03:23AM
(#7129366)
Similarly &> works for redirecting both stderr and stdout to a file. >& is the alternate, less preferred syntax.
Re:Results of the Grand C++ Error Explosion Competition
by mrich on Monday January 27, 2014 @01:24AM
(#7129098)
Perhaps it will help you to understand some background:
In a Unix process stdout typically is file descriptor 1 and stderr is fd 2. So you are saying: Redirect from fd 2 into fd 1.
Re:Results of the Grand C++ Error Explosion Competition
by 0x0 on Monday January 27, 2014 @07:37AM
(#7129993)
The biggest problem is mixing up >& and &> ...which ends up leaving a bunch of files called "1" around with a runaway background process :(
Re:Results of the Grand C++ Error Explosion Competition
by coldpie on Monday January 27, 2014 @09:17AM
(#7130351)
Yeah, it's tricky. I remember it by breaking it into two pieces. "2>" means redirect stderr (file descriptor 2) to the following token. "&1" is the token for stdout (kinda like the address-of operator). So taken together, "2>&1" means redirect stderr to stdout.
Bash-only shortcuts like &> don't improve the situation :)