Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2007
    Posts
    11

    Unanswered: Help with exec command and file descriptors??

    im having trouble with the comprehending the exec command and the use of file descriptors.
    given:

    #!/bin/sh

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

    echo Hello

    would the standard output of this script be sent to STDOUT, STDERR or neither and why???

    thanks for the help.

  2. #2
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    It will swap stdout and stderr
    Think of it as assigning variables
    to start
    a=1
    b=2
    Now in the script you do
    d=$a
    a=$b
    b=$d
    So now
    a=2 and b=1

  3. #3
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    PS. You could use one exec command as it is evaluated left to right i.e.
    exec 4>&1 1>&2 2>&4 4>&-

    For more info see
    http://bash-hackers.org/wiki/doku.ph...ction_tutorial

Posting Permissions

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