Bash for beginners @ TLDP.ORG, chapter 8, question
According to the guide:
ls -l * 2> /var/tmp/unaccessible-in-spool will redirect standard output of the ls command to the file unaccessible-in-spool in /var/tmp. I can't get that to be correct, if I issue such a command I get an empty file and standard output on the screen. Ideas ? |
`command 2> file` means that stderr will be redirected to "file"
`command 1> file` is for redirecting stdout to "file" Cheers. |
Yes. There is no message sent to the standard error. When you use redirection to a file, the file is created when the command execution starts, so that it can rest unused if no error message comes out from the execution. If you want to redirect the standard output together with the standard error you can do this:
Code:
ls -l * > /var/tmp/unaccessible-in-spool 2>&1 You can also try a different command to see the standard error file populated by an error message: Code:
ls -l pippo 2> /var/tmp/unaccessible-in-spool |
Bash also supports
`command &> file` for redirecting both stdout and stderr into "file". Other shells (such as dash) may or may not support this. |
Thanks for all help.
I actually agree 100% with my result and with you. when a command that produces no errer redirects that non-existent errer to a file, I expect it to be empty. What confused me was that the guide said that "2>" would redirect stdout, which it doesn't. |
Must be a typo in the guide. It happens... sometimes you can't trust the book...
|
All times are GMT -5. The time now is 10:43 PM. |