Yesterday I read this SO comment which says that in the shell (at least
>&- "has the same result as"
That comment actually refers to the ABS guide as the source of its information. But that source says that the
>&- syntax "closes file descriptors".
It is not clear to me whether the two actions of closing a file descriptor and redirecting it to the null device are totally equivalent. So my question is: are they?
On the surface of it it seems that closing a descriptor is like closing a door but redirecting it to a null device is opening a door to limbo! The two don't seem exactly the same to me because if I see a closed door, I won't try to throw anything out of it, but if I see an open door I will assume I can.
In other words, I have always wondered if
>/dev/null means that
cat mybigfile >/dev/null would actually process every byte of the file and write it to
/dev/null which forgets it. On the other hand, if the shell encounters a closed file descriptor I tend to think (but am not sure) that it will simply not write anything, though the question remains whether
cat will still read every byte.
This comment says
>/dev/null "should" be the same, but it is not so resounding answer to me. I'd like to have a more authoritative answer with some reference to standard or source core or not...