What is 2>&- mean
In my linux system , there is a script that have a 2>&- , I know this is to handle error message , can advise what is this mean ?
Thanks. |
Hello,
It is just piping STDERR to the background, running it in the background using the & sign. Have a look here - http://en.wikipedia.org/wiki/Standard_streams Always remember the following file descriptors: Code:
0 - STDIN Josh |
Thx reply,
what is - sign mean ? |
Could you show me what the script does, and what output you get? I honestly never used a - with file descriptors.
|
Quote:
http://wiki.bash-hackers.org/syntax/redirection |
Quote:
|
Nevertheless there is a difference in closing the file descriptor or redirecting it to /dev/null. To /dev/null you can write to, while writing to a closed file descriptor yields write error: Bad file descriptor.
I would even say the alternative way explained in http://wiki.bash-hackers.org/syntax/redirection is not clean, as the error about not being able to write to stdout can’t also be output. As a consequence the return code of an application made quiet this way might be wrong (i.e. indicating an error). N.B. It’s in the bash man page in the section about copying file descriptors. |
Quote:
|
It was late this morning. Now with a fresh “proof of error”:
Code:
$ ls >&- The syntax is fine in case you close a file descriptor you no longer need: Code:
$ exec 5>foobar |
All times are GMT -5. The time now is 12:43 PM. |