Bash tail -f 带有 while-read 和管道挂起

Eri*_*son 4 bash pipe tail

在 Bash 中,管道tail -fread循环会无限期地阻塞。

while read LINE0 
do 
    echo "${LINE0}"; 
done < <( tail -n 3 -f /tmp/file0.txt | grep '.*' ) 
# hangs
Run Code Online (Sandbox Code Playgroud)

删除-for | grep '.*',然后循环将迭代。

以下就不会挂。

tail -n 3 -f /tmp/file0.txt | grep '.*' 
Run Code Online (Sandbox Code Playgroud)

是什么导致了这种行为?

无论如何,Bash 是否可以跟踪文件并读取管道表达式?

Ipo*_*cer 15

tail -n 3 -f /tmp/file0.txt | grep --line-buffered '.*' | while read LINE0 
do 
    echo "${LINE0}"; 
done 
Run Code Online (Sandbox Code Playgroud)