![]() |
|
|
|
|
|||||||
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
a question
I was experimenting with redirection. Manual says
>&digit --> standard output is redirected to the file descriptor digit I tried exec 3>myout exec >&3 This sent all the output to myout. Nothing was coming on the screen. I was thinking duplication will result in output similar to what tee gives. Am I wrong in understanding? One more thing. Once I have redirected this to 3, How do I disable it or how do I redirect the output back to screen again. |
| Forum Sponsor | ||
|
|
|
|||
|
still not
When I do
Code:
exec >&2 |
|
|||
|
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 |