TransWikia.com

Bash tail -f with while-read and pipe hangs

Unix & Linux Asked by Eric Larson on November 23, 2021

In Bash, piping tail -f to a read loop blocks indefinitely.

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

Remove the -f or | grep '.*', then the loop will iterate.

The following does not hang.

tail -n 3 -f /tmp/file0.txt | grep '.*' 

What causes this behavior?

Is there anyway in Bash to follow a file and read in a pipe expression?

One Answer

tail -n 3 -f /tmp/file0.txt | grep --line-buffered '.*' | while read LINE0 
do 
    echo "${LINE0}"; 
done 

Answered by Ipor Sircer on November 23, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP