exec 6>&1 will copy file descriptor 1 onto 6.

But how can I copy both stderr and stdout (1 and 2)to file descriptor 6 ?

migrated from serverfault.com Oct 10 '14 at 21:25

This question came from our site for system and network administrators.

  • exec 1>./all.txt exec 2>./all.txt – c4f4t0r Oct 10 '14 at 13:24

Redirect stdout to 6 and stderr to stdout (so it will be further redirected to 6):

command >&6 2>&1

I don't think you can redirect two files descriptors in one, but you can use two files descriptors pointing to one file

exec 1>./all.txt
exec 2>./all.txt
  • 2
    bash allows the special case of &> ./all.txt to redirect stdout and stderr at the same time. – chepner Oct 12 '14 at 15:19

Try with:

command &>&6

    # Redirect both stdout and stderr to file "filename."  
    # This operator is now functional, as of Bash 4, final release.  
    # "M" is a file descriptor, which defaults to 1, if not set.  
    # "N" is another file descriptor.  
  • Unfortunately, &> does not allow you to duplicate two file descriptors into one; it only allows you to redirect to a file. – chepner Oct 12 '14 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy