I create a pipe using
mkfifo /tmp/foo.pipe
Now, I want to try reading from the pipe for a maximum of 2 seconds, so I execute
read -t 2 line < /tmp/foo.pipe
The timeout does not occur. Read just sits there waiting for input from the pipe.
The manuals say that ‘read’ is supposed to work with named pipes. Does anyone have an idea why this is happening?
ls -al /tmp/foo.pipe
prw-r----- 1 foo bar 0 Jun 22 19:06 /tmp/foo.pipe
Your shell is blocking on the open() call before invoking the read builtin.
On Linux, you can open the FIFO for both read and write at the same time to prevent blocking on open; this is non-portable, but may do what you want.
Adapted from: Bash script with non-blocking read