Saturday, October 13, 2007

Redirection In *nix

After having gone through "search implement and forget" cycle of redirection in *nix environment. I thought it will be best in my interest to just make a small note on it on my blog. So that I have it at an easy to remember and accessible place.

To redirect both stderr and stdout streams on a bash shell you need to do:
command args >& logFile

To redirect only the stderr you should do only:
command args 2> logFile

NOTE: If you invoke a subshell like:
sh shell_script
Then you should encapsulate the command within apostrophe(') to prevent the parent shell interpreting and converting the stderr stream to an integer. This is because, if you invoke your script in the aforementioned way, then the parent shell invokes a child shell and tries to do substitutions where ever possible.

I should be explaining this more in detail in future, maybe :)

No comments: