Find the answer to your Linux question:
Results 1 to 5 of 5
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    how to redirect inside bash script, BUT...

    I want to do the following redirectin inside a bash script :
    1. all the stdout will be redirected to a /tmp/log
    2. all the errors will go to the stderr and also to the /tmp/log.

    The following inside a bash script is not working, WHY and HOW to do it:

    exec 1>/tmp/log
    exec 2> > (tee -a /tmp/log)
    rest of the bash script.

  2. #2

    Experts on bash Redirections?

    Anyone can help on that?

  3. #3

  4. $spacer_open
  5. #4

    Redirection issue

    I didn't find the answer to my question in the link(BASH Programming - Introduction HOW-TO: All about redirection).

    This link has a basic redirection example, and want I need it a bit complicated redirection issue.

  6. #5
    I think what you'll have to do is create a child process running tee and use a named pipe to redirect stderr to it. That way stderr will print on the terminal and to the log.

    trap "rm -f $npipe" EXIT
    # Delete named pipe on script exit
    mknod $npipe p
    # Create the named pipe
    tee <$npipe -a /tmp/log &
    # Create child process running tee with stdin redirected to named pipe
    exec 1>/tmp/log
    # Redirect stdout to log
    exec 2>&-
    # Close stderr
    exec 2>$npipe
    # Open stderr on named pipe

Posting Permissions

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