The UNIX and Linux Forums  

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


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 !!

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-23-2006
Playing with Ubuntu Now!
 

Join Date: Oct 2005
Location: Chennai
Posts: 363
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
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.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-24-2006
Registered User
 

Join Date: Sep 2005
Location: india
Posts: 78
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
have done this
exec >&2
Reply With Quote
  #3 (permalink)  
Old 05-24-2006
Playing with Ubuntu Now!
 

Join Date: Oct 2005
Location: Chennai
Posts: 363
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
still not

When I do
Code:
exec >&2
It is over-riding the previous duplication. After this, the o/p comes back to screen, but no output goes to the file. But since 2 is stderr stream, what happens if that was redirected elsewhere.
Reply With Quote
  #4 (permalink)  
Old 05-24-2006
Registered User
 

Join Date: Mar 2006
Location: South Yorkshire, UK
Posts: 114
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
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
  #5 (permalink)  
Old 05-25-2006
Playing with Ubuntu Now!
 

Join Date: Oct 2005
Location: Chennai
Posts: 363
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
that is clear

I understand what you said, thestevew. Then, how does 'tee' achieve its functionality.
Reply With Quote
  #6 (permalink)  
Old 05-25-2006
reborg's Avatar
Administrator
 
Join Date: Mar 2005
Location: Ireland
Posts: 3,407
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
It opens an extra file descriptors to write to the file.
Reply With Quote
  #7 (permalink)  
Old 05-25-2006
Playing with Ubuntu Now!
 

Join Date: Oct 2005
Location: Chennai
Posts: 363
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
so

So, it does not depend on redirection(like I was thinking). Then it is a little clear now. Thanks a lot.
Reply With Quote
  #8 (permalink)  
Old 05-25-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,279
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Read the man pages on dup and dup2
Those are the system calls involved in redirection and tee.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:50 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101