Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的 bash 脚本中有一个代码
OUTPUT=""yum update
echo $OUTPUT
echo $OUTPUT >> mylogfile
yum update是一个很长的命令,没有我的脚本,它总是向控制台输出一些东西,但是在我的脚本中它开始了,很长一段时间没有输出,过了一会儿输出了很多数据。我的脚本中有什么方法可以在数据可用时立即输出数据,但在长时间等待后并非所有数据都在同一时间输出?
yum update
尝试使用tee:
$ yum update | tee mylogfile
将从 yum 发送标准输出到shell(你的屏幕)和mylogfile. 根据需要为标准错误添加重定向。
mylogfile