Note that I have reviewed both stackoverflow questions below, but my question is different:
- redirect COPY of stdout to log file from within bash script itself
- redirect stdout and stderr to one file, copy of just stderr to another
In attempting to do this, I have the following test.sh script:
#!/bin/bash
rm stdout_and_stderr.log
rm stderr.log
exec 2> >(tee -ia stderr.log >> stdout_and_stderr.log) 1> >(tee -ia stdout_and_stderr.log)
echo "stdout"
echo "stderr" >&2
The only problem is that stderr is not displayed to terminal:
$ ./test.sh > /dev/null
$ ./test.sh 2> /dev/null
$ stdout
My version of bash:
GNU bash, version 4.2.46(1)-release (x86_64-redhat-linux-gnu)