Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2006
    Posts
    1

    Question Unanswered: 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

  2. #2
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •