首页 > 编程知识 正文

linux shell使用环境变量,华为watch 3设置24小时制

时间:2023-05-06 03:53:30 阅读:258092 作者:3358

I was wondering if it was possible to tell bash that all calls to echo or printf should be followed up by a subsequent call to fflush() on stdout/stderr respectively?

我想知道是否有可能告訴bash所有對echo或printf的調用應該分別跟隨stdout / stderr上的fflush()后續調用?

A quick and dirty solution would be to write my own printf implementation that did this and use it in lieu of either built in, but it occurred to me that I might not need to.

一個快速而骯臟的解決方案是編寫我自己的printf實現,並使用它來代替內置的,但它發生在我身上,我可能不需要。

I'm writing several build scripts that run at once, for debugging needs I really need to see messages that they write in order.

我正在寫幾個同時運行的構建腳本,為了調試需求,我真的需要看到它們按順序寫入的消息。

3 个解决方案

#1

10

If comands use stdio and are connected to a terminal they'll be flushed per line. Otherwise you'll need to use something like stdbuf on commands in a pipe line http://www.pixelbeat.org/programming/stdio_buffering/

如果命令使用stdio並連接到終端,則每行都會刷新它們。否則你需要在管道中的命令上使用stdbuf之類的東西http://www.pixelbeat.org/programming/stdio_buffering/

tl;dr: instead of printf ... try to put to the script stdbuf -o0 printf .., or stdbuf -oL printf ...

tl; dr:而不是printf ...嘗試將腳本stdbuf -o0 printf ..或stdbuf -oL printf ...

#2

1

If you force the file to be read, it seems to cause the buffer to flush. These work for me.

如果強制讀取文件,則似乎會導致緩沖區刷新。這些對我有用。

Either read the data into a useless variable:

將數據讀入無用的變量:

x=$(

Or do a UUOC:

或者做一個UUOC:

cat $logfile > /dev/null

#3

0

Maybe "stty raw" can help with some other tricks for end-of-lines handling. AFAIK "raw" mode turns off line based buffering, at least when used for serial port ("stty raw < /dev/ttyS0").

也許“stty raw”可以幫助一些其他的線端處理技巧。 AFAIK“原始”模式關閉基於行的緩沖,至少在用於串行端口時(“stty raw

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。