小编Abh*_*pta的帖子

sh shell:将输出重定向到终端和脚本内的文件

如何从脚本内部将 stdout 和 stderr 重定向到文件和终端。

#!/bin/sh

LOG_FILE="/tmp/abc.log"

exec &> >(tee -a $LOG_FILE)

echo "Start"
echo "Hi" 1>&2 
echo "End"
Run Code Online (Sandbox Code Playgroud)

我找到了上面的脚本。但是这个脚本只适用于 bash。使用 sh shell 会出现以下错误:

./abc.sh: 5: Syntax error: redirection unexpected (expecting word)
Run Code Online (Sandbox Code Playgroud)

我想要一个同时适用于 sh 和 bash shell 的脚本。

shell logs io-redirection shell-script

8
推荐指数
1
解决办法
432
查看次数

标签 统计

io-redirection ×1

logs ×1

shell ×1

shell-script ×1