Linux 更改bash IO缓冲区设置

Linux 更改bash IO缓冲区设置,linux,bash,io,Linux,Bash,Io,我的代码如下: mkfifo test.pipe # execute another program at this point. it reads test.pipe(readonly), and falls asleep. # the program will respond line by line. exec 4>test.pipe echo hello world >&4 但是我发现程序不会响应,因为fd4中的hello world没有刷新。我认为bash使用块缓

我的代码如下:

mkfifo test.pipe
# execute another program at this point. it reads test.pipe(readonly), and falls asleep.
# the program will respond line by line.
exec 4>test.pipe
echo hello world >&4
但是我发现程序不会响应,因为fd
4
中的
hello world
没有刷新。我认为bash使用块缓冲区打开此文件,因此即使我在这里有
\n
,消息也不会被刷新

所以我的问题是,如何使
4
不缓冲或行缓冲

请注意,我不喜欢

echo hello world! >test.pipe
因为程序将读取eof,这不是我的期望

更新:


或者任何其他方式,我只是不希望程序端的EOF发生得太频繁(否则会爆发额外检查)。

不理解这个问题,因为

mkfifo test.pipe

sed 's/.*/i am the sed>>&<</' < test.pipe &   #pipe reader in bg

exec 4>test.pipe

for i in {1..5}
do
echo "$i to pipe wihout NL sleeping 2 secs"
echo -n hello world $i >&4
sleep 2
echo "now the NL - and the sed responds"
echo >&4
sleep 0.5
echo =====
done
mkfifo test.pipe

sed的/*/i是sed>&stdbuf
命令帮不上忙?(缺点-必须将其包括在每个输出重定向中)@jm666仅适用于标准io?如何处理我的要求?
(echo hello world>&4)
应该确保消息被刷新,但它是一个相当大的锤子(子壳),用于固定小螺母。我假设“另一个程序”是在后台运行的,或者没有阻止
exec
echo
的执行。@JonathanLeffler当然是在后台运行的。我完全按照“原样”运行您的代码,它工作正常,所以问题可能出在其他地方。顺便说一下,fifo实际上是行缓冲的。哦,真的吗?!我用8个字节的消息循环了1024次,让对方接收我的数据。我开始想,也许我的系统出了问题。