我正在写一个bash脚本,并使用下面的技巧到标准输出重定向到由三通消耗命名管道:进程替换返回提示
exec > >(tee -a $LOGFILE) 2>&1
然而,脚本退出时,它不返回壳,直到我按下输入。有没有简单的方法来解决这个问题,同时仍然使用这种方法?
编辑:这是我在这个运行环境:简单的脚本的
Centos 7
Bash version 4.2.45
内容称为redirect.sh:
#!/bin/bash
exec > >(tee -a /tmp/haha) 2>&1
echo "hi there"
exit 0
样品会话:
[[email protected] ~]# ./redirect.sh
[[email protected] ~]# hi there
[[email protected] ~]#
未经测试:您退出脚本之前,关闭输出:'EXEC 1>& - 2>& - ' - 可能会关闭发球台。 –
感谢您的评论,但它不起作用。 – duffsterlp
我建议你用'set -x'运行你的脚本,这样你就可以看到发生了什么事情。我认为stdout重定向不需要你输入。 –