Look at this code:
while read -t 3 line; do
echo ${line}
done < /opt/data.log
data.log
is a fifo. One process is writing to this, and this code should be reading it to show to the user. But I want it to exit when there is no more data in the fifo for 3 seconds.
The problem is it never times out. I write to this fifo, it shows me:
read: 6: Illegal option -t
What is wrong?
[UPDATE]
Yes, I was using /bin/sh
as a shebang which is a symbolic link to dash
. I changed it to /bin/bash
. but it does not make any benefit. It waits for ever if no one opens the fifo. I want a timeout solution that works when the other end of the fifo has not opened it.
read
isn't executing yet. The redirection has to open the FIFO before the loop can start, and the open is blocking. You need a timeout on the redirection operator. I can't think of a good way to do that... – Alan Curry Jul 28 '12 at 05:20