Is it possible to do selects or polls on file descriptors in bash? The essence of what I’m trying to do is this:
mkfifo fifo
exec 3<fifo
PROMPT_COMMAND="while read -t 0 line; do echo \$line; done <&3"
The exec is there to keep the pipe open (otherwise it would be closed at the end of each loop). In theory, this would output anything entering the pipe before each prompt. However, it doesn’t seem to work, as with -t0 it doesn’t even try to read.
-t 1 works like a charm, but that forces a one second delay at every prompt, which is not what I want.
Optimal would be to do a select with .2 seconds timeout (if i’m executing a command which in turn causes something to be written to the pipe, there’s bound to be a short delay as I’m working with asynchronous messages), and that delay I can live with. Zero timeout would probably be ok, then I’ll just create a program to have a subsecond delay.
Any ideas?
I stumbled on this today, and it actually solves my problem quite elegantly.
screenallows the current terminal window to be split, where I can reduce one part of the window to just a couple of lines, where I keep my input, and justcat fifoin the other part of the window.Screen definitely rocks a lot more than I already knew (detach alone makes it one of the best tools ever).