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?
'Select' command is a very useful bash command for bash menu creation. Different types of menu generation task, creating menu based director list, creating a menu from file content etc. can be done using bash select command.
$_ (dollar underscore) is another special bash parameter and used to reference the absolute file name of the shell or bash script which is being executed as specified in the argument list. This bash parameter is also used to hold the name of mail file while checking emails.
$1 means an input argument and -z means non-defined or empty. You're testing whether an input argument to the script was defined when running the script.
The select statement allows users to choose from multiple options by default and it will prompt the user for an input. You do not have to write any code to accept user input as the select loop is pre-built to handle it. This loop can be used to make menus within your script while keeping the script looping infinitely.
I stumbled on this today, and it actually solves my problem quite elegantly. screen
allows 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 just cat fifo
in 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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With