The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-24-2006
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
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.
  #2 (permalink)  
Old 05-24-2006
Raom Raom is offline
Registered User
  
 

Join Date: Sep 2005
Location: india
Posts: 79
have done this
exec >&2
  #3 (permalink)  
Old 05-24-2006
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
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.
  #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
  #5 (permalink)  
Old 05-25-2006
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
that is clear

I understand what you said, thestevew. Then, how does 'tee' achieve its functionality.
  #6 (permalink)  
Old 05-25-2006
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,190
It opens an extra file descriptors to write to the file.
  #7 (permalink)  
Old 05-25-2006
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
so

So, it does not depend on redirection(like I was thinking). Then it is a little clear now. Thanks a lot.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 08:17 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0