If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > exec >&- 2>&- # Close stdout and stderr

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-18-06, 05:32
teenu18 teenu18 is offline
Registered User
 
Join Date: Sep 2006
Posts: 1
Question exec >&- 2>&- # Close stdout and stderr

Hi,

I find this in one of the automated shells with this comment.
exec >&- 2>&- # Close stdout and stderr

Can any one explain to me about this command the usage of it please?

Thanks in advance.

Regards,
Teenu
Reply With Quote
  #2 (permalink)  
Old 09-20-06, 03:11
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
You don't normally need to close stdout and stderr
It happens automatically when your script ends
here is an example using exec to redirect
if you want to save the current setting of stout and stderr
whether it be to a file or to the screen
then redirect to somefile and then redirect back to them

exec 3>&0 4>&1 >somefile 2>&1

This saves the old stdout on FD 3, and the old stderr on FD 4.

exec 1>&3 2>&4 3>&- 4>&-

This copies 3 back to stdout and 4 back to stderr, then closes the
descriptors that are no longer needed.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On