Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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:
It is just piping STDERR to the background, running it in the background using the & sign.
Incorrect. The &-closes the designated file descriptor. So what it's doing is turning stderr completely off, instead of redirecting it into /dev/null or similar, as scripters usually do.
Incorrect. The &-closes the designated file descriptor. So what it's doing is turning stderr completely off, instead of redirecting it into /dev/null or similar, as scripters usually do.
Ahh, I didn't know that about the dash. Thanks for that man, I even tried looking for that online, but didn't know what it was called, along with being part of the file descriptors.
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.
Last edited by Reuti; 09-21-2011 at 04:36 AM.
Reason: Clarified the return code indicating an error / Typo
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 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.
Ahh, that's why I couldn't find it, I was looking in the wrong places. But after doing the research and fully understanding what it does and how it works, yeah that is true on what you said. You could always run the output before hand to redirect, in that case, to get the output redirected properly.
It was late this morning. Now with a fresh “proof of error”:
Code:
$ ls >&-
ls: write error: Bad file descriptor
$ echo $?
2
$ ls >/dev/null
$ echo $?
0
Same behavior on AIX: so I think it’s not wise to disregard the output this way. Interesting though, that on Mac OS X it’s really just working as advertised. But I would even this judge as an error: it shouldn’t be possible to write to a closed file descriptor without notifying the user about the error (even a test whether /dev/stdout is writable succeeds, but maybe it’s the way BSD works).
The syntax is fine in case you close a file descriptor you no longer need:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.