【发布时间】:2016-03-29 11:27:34
【问题描述】:
请注意,我已经查看了以下两个 stackoverflow 问题,但我的问题有所不同:
- 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
在尝试执行此操作时,我有以下 test.sh 脚本:
#!/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
唯一的问题是stderr没有显示到终端:
$ ./test.sh > /dev/null
$ ./test.sh 2> /dev/null
$ stdout
我的 bash 版本:
GNU bash, version 4.2.46(1)-release (x86_64-redhat-linux-gnu)
【问题讨论】:
-
问题解决了吗?
标签: bash shell io-redirection