linux – tee命令无法正常工作(带有read和echo)
发布时间:2020-12-30 12:26:40 所属栏目:Linux 来源:互联网
导读:脚本和输出如下: 脚本: #!/bin/bash#tee_with_read.shfunction tee_test(){ echo ***This should be printed first but it is not*** read -r -p Enter input : echo You entered : $REPLY}tee_test
脚本和输出如下: 脚本: #!/bin/bash #tee_with_read.sh function tee_test() { echo "***This should be printed first but it is not***" read -r -p "Enter input : " echo "You entered : $REPLY" } tee_test | tee -a logfile 输出: $./tee_with_read.sh Enter input : ***This should be printed first,but it is not*** "My Input" You entered : "My Input" 我正在尝试将输出附加到logfile. 我在Windows 10上使用Git Bash版本3.1.23. 解决方法read -p将它的输出写入stderr,echo正在写入stdout. stdout通常是缓冲的,而stderr则没有,因此在stdout之前看到stderr事件的情况并不少见.如果你喜欢做回声“字符串”>& 2你可以让你的回声也转到stderr,或者你可以在unbuffer命令或类似的工具中运行它,如果你有它们可用的话 (编辑:台州站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |