Without answering your specific question, you need to run something like
read -t 3 variable < <( tail -f logfile.log | grep "something" )
so that the new variable setpoint is visible after the completion of the pipeline. See if this deadline expires.
Since you just use read as a way to exit the pipeline after a certain time, you donβt have to worry about the variable scope. However, grep can find a match without printing it for a timeout due to its own internal buffering. You can disable this (with GNU grep , at least) using the --line-buffered option:
tail -f logfile.log | grep --line-buffered "something" | read -t 3
Another option, if available, is the timeout command as a replacement for read :
timeout 3 tail -f logfile.log | grep -q --line-buffered "something"
Here we kill tail after 3 seconds and usually use the grep exit status.
source share