无缓冲的Bash输出 [英] Unbuffered Bash Output

查看:52
本文介绍了无缓冲的Bash输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个bash脚本,我正在尝试使用它编写无缓冲的输出.我有这样的东西:

I have a bash script that I'm trying to write unbuffered output with. I have something like this:

...
mkfifo $PIPE
for SERVER in ${SERVERS[@]}; do
    ssh $SERVER command >$PIPE &
done

while read LINE; do
    echo ${LINE}
done <$PIPE

问题是脚本的所有输出都被缓冲了.

The problem is that all of the output of the script is buffered.

我知道我可以在整个脚本中使用诸如 stdbuf unbuffer 之类的东西,但是我不希望我的用户必须运行 stdbuf -o0每次-e0 my_command .

I know I can use something like stdbuf or unbuffer to the whole script, but I don't want my users to have to run stdbuf -o0 -e0 my_command every time.

是否可以在脚本中实现这种效果?

Is there a way to achieve that effect within my script?

谢谢,马克

推荐答案

为什么不创建一个别名来运行 stdbuf ,这又将取消缓冲脚本输出?

Why not create an alias to run stdbuf, which will in turn unbuffer the script output?

我了解您不希望用户使用 stdbuf 手动输入命令.为什么不让用户创建一个别名,该别名将执行运行脚本的 stdbuf ?

I understand you don't want the user to manually input the command with stdbuf. Why not let the user create an alias which will execute stdbuf running the script?

alias my_script='stdbuf -o0 -e0 <path_to_script>'

现在,用户可以从终端运行脚本(终端也可以帮助填写脚本名称),如下所示:

Now users can run the script from the terminal (terminal can also help to fill out script name) as follows:

my_script

这篇关于无缓冲的Bash输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆