3

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 ?

1
  • exec 1>./all.txt exec 2>./all.txt
    – c4f4t0r
    Commented Oct 10, 2014 at 13:24

3 Answers 3

4

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

command >&6 2>&1
0

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
1
  • 2
    bash allows the special case of &> ./all.txt to redirect stdout and stderr at the same time.
    – chepner
    Commented Oct 12, 2014 at 15:19
-1

Try with:

command &>&6

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

You must log in to answer this question.