【发布时间】:2022-01-13 19:44:08
【问题描述】:
我有一个类似下面的脚本:
#!/bin/bash
#func.sh
func(){
badcommand1
echo "OK"
badcomand2
}
func 2>&1 > err.log
#The top line is in the file
我的目标是将所有输出和错误重定向到文件 err.log 但不幸的是,它只打印 “OK”到日志文件。
Bash 版本是: GNU bash,版本 4.2.46(2)-release (x86_64-redhat-linux-gnu)
有人可以帮忙吗?
【问题讨论】:
-
请注意,问题标题用词不当——您是在函数外部而不是内部进行重定向。
标签: bash shell stdout io-redirection stderr