4 ms·
make 2>&1 | head (or less) is a common occurrence in my .bash_history :(
by jacobparker 13y ago
make 2>&1 | head (or less) is a common occurrence in my .bash_history :(
- waynecochran 13y agoI actually have this written on the corner of my whiteboard because I can never remember bash's syntax for piping out stderr!
- JoshTriplett 13y agoIf you don't mind being bash-specific, you can shorten 2>&1 | to just |& .
- coherentpony 13y agoGood lord. I think you just changed my life.
- praptak 13y agoSimilarly &> works for redirecting both stderr and stdout to a file. >& is the alternate, less preferred syntax.
- daxelrod 13y agoThe phrase "two greater amper one" seems to help me. My tendency otherwise is to type the ampersand before the greater-than.
- mrich 13y agoPerhaps 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.
- 0x0 13y agoThe biggest problem is mixing up >& and &> ...which ends up leaving a bunch of files called "1" around with a runaway background process :(
- coldpie 13y agoYeah, 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 :)