redirecting stderr to file
Hi,
I want to store bash's debug information into a file like this: bash -x bashscript.sh 2>&1 > debug.log But when I open debug.log, the stderr info isn't there. example: $ cat example.sh #!/bin/bash echo hi $ bash -x example.sh 2>&1 > debug.log + echo hi $ cat debug.log hi $ It seems that there is a hidden channel that outputs "+ echo hi" to the terminal. I tried to find it, but I was unsuccessful. |
The order is important. If you redirect standard error to standard output without previously redirecting standard output to a file, standard error still goes to the terminal. The following should work
Code:
bash -x bashscript.sh > debug.log 2>&1 |
it still confuses me.
|
Why? When you specify
Code:
2>&1 Code:
2>&1 # standard error is redirected to standard output Code:
> some_file # equal to 1> some_file |
So:
bash -x bashscript.sh 2>&1 > debug.log is basicly the same as: bash -x bashscript.sh > debug.log because errors go to the terminal by default. I see it this way, because you are already writing to the file (because it is at the front of the command), all other redirections that come later, pointing to channel 1, will be added to the file (because channel 1 is already being redirected). Thanks for the explanation colucix! |
All times are GMT -5. The time now is 08:58 AM. |