gpt4 book ai didi

linux - 如何将单个命令的输出重定向回显示器

转载 作者:太空狗 更新时间:2023-10-29 11:34:05 25 4
gpt4 key购买 nike

在我的 shell 脚本中

LOG=/my.log
exec 1>>$LOG
exec 2>&1

重定向 shell 脚本中的输出。现在问题出在下面

LOG=/etc/security/aixpert/log/aixpert.log
exec 1>>$LOG
exec 2>&1

#some codes

print "I want this on cmd output not in log"

#I want rest of the output redirected to log as usual

我该怎么做?

最佳答案

关键是克隆 stdout 到控制台到任意 fd(我选择 3),然后再将其重定向到您的日志。每当您想将输出发送到控制台时,只需使用 >&3 将 fd 1 重定向回 fd 3 即可

LOG=/etc/security/aixpert/log/aixpert.log

exec 3>&1 >>"$LOG" 2>&1

#some codes

echo "I want this on cmd output not in log" >&3

#I want rest of the output redirected to log as usual

关于linux - 如何将单个命令的输出重定向回显示器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8725516/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com