Linux管道

Linux管道

从bash版本4开始,您可以使用 |& 作为缩写 2>&1 |
但此时错误返回码不能被抛出,做类似如下处理即可得到:
[root@localhost ~]# xx |& tee > xx && (exit ${PIPESTATUS[0]}) && echo ok || echo no
no
[root@localhost ~]# ls |& tee > xx && (exit ${PIPESTATUS[0]}) && echo ok || echo no
ok

./aaa.sh |& tee -a log	等价于	./aaa.sh 2>&1 | tee -a log

tee -
输出到标准输出两次。
tee 输出到多个文件,只需多个管道即可,如:
echo "test"  | tee  1.txt  | tee -a  2.txt	#1.txt覆盖,2.txt追加