3 ms·
> You could redirect 4>&1 1>/dev/null For anyone confused by this, 1 is the output to stdout, and 4 is being redirected to where 1 goes, which is stdout. Unrel
by oarsinsync 5y ago
> You could redirect 4>&1 1>/dev/null
For anyone confused by this, 1 is the output to stdout, and 4 is being redirected to where 1 goes, which is stdout. Unrelated to that, 1 (what’s actually being output to stout by the application) is being redirected to /dev/null.
The order of operations matters. If 1 was redirected to /dev/null first, then 4 would also end up in /dev/null. As it stands now, that doesn’t happen.
- tgv 5y agoGood one. I did look it up before I posted, too. I’m never 100% sure.
- im3w1l 5y agoSo you are supposed to read it from right to left? "First take 1 and throw it away. Next put 4 in 1." Is that how it works?
- kubanczyk 5y agoNot quite. Left to right: copy the descriptor 1 onto descriptor 4, change descriptor 1 to result of open("/dev/null"). The >& is for copying the descriptor not for aliasing ("hardlinking") it. The descriptor is the "fd" argument, e.g.: write(int fd, const void *buf, size_t count)
- vultour 5y agoNo, it’s like assigning variables. The second part overwrites the value of 1, but the first part is still using the old value.
- dgrunwald 5y agoNo, it's from left to right. It's basically just syntax for a series of dup2() calls. "4>&1 1>/dev/null" means: streams[4] = streams[1]; streams[1] = open("/dev/null");