Question 1. What will happen if we close a input file descriptor as if it is a output file descriptor? (or vice versa).
$ exec 5<&2 $ exec 5>&-
In my linux box, any error does not happen on sh and bash. And POSIX seems not to say we SHOULD close input file descriptos with
The redirection operator:
... If word evaluates to '-', file descriptor n, or standard input if n is not specified, shall be closed. Attempts to close a file descriptor that is not open shall not constitute an error. ...
So is it also a correct way that to close a input file descriptor as if it is for output?
Question 2. If the above code is wrong and we should close a input file descritor with
<-, how can we close a file descriptor for reading and writing?
$ exec 5<>&file $ #How to close the file descritor 5?
Question 3. According to the above POSIX specification, we shall not see any error when we attempt to close a file descriptor that is not open. What is the merit of this way?