The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM



Thread: a question
View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 05-24-2006
thestevew thestevew is offline
Registered User
 

Join Date: Mar 2006
Location: South Yorkshire, UK
Posts: 114
Redirection does just what it says on the tin, it re-directs a data stream that was going to (or coming from) one place (e.g. your screen) to (or from) somewhere else (e.g. a file).

Your command:

exec >&2

sends std out (stream 1) to the same place as std err (stream 2) - it's really a shorthand for exec 1>&2

You do have to make sure that you specify redirections in the right order as they are acted on from left to right.

Examples

If you redirect std out (1) to go to wherever std err (2) is going, then redirect std err to a file then std out will continue to go to std err's default destination (i.e. the screen) and std error will be captured in the file (and you won't see it on screen)!

exec >&2 2>mylog.txt


However, put the redirections the other way round and std err is first directed to a file then std out is sent to wherever std err is currently directed. This time, both will end up in the file and you will see nothing on screen:

exec 2>mylog.txt >&2


If you start to feel dizzy then a lie down in a darkened room usually helps

cheers
Reply With Quote