I have an old script shell that needs to be moved to bash. This script prints the progress of some actions and waits for user commands. If the user does not take any action within 15 seconds, he redraws with a new progress, and the timer starts again. Here is my problem:
I'm trying to use read -t 15 myVar- this way, after 15 seconds, the wait loop will restart. However, there is a script that causes me a problem:
- the screen is redrawn and the script is waiting for input (displays
Enter command:') - user enters
foobut does not clickenter - after 15 seconds, the screen is redrawn again, and the script is waiting for input - note that it
foodoes not appear anywhere on the screen (prints " Enter command:") - user enters
barand clicksenter
At this point, the variable $myVarcontains. ' foobar'
What I need? I am looking for a way to find the first line typed by the user, so I was able to re-display it after updating the status. Thus, the user will see:
Enter command: foo
In Solaris, I could use stty -pendinto save the input in some kind of buffer and after updating stty pendin, to get this input from the buffer and print it on the screen.
Is there a Linux equivalent for a function stty pendin? Or maybe you know a bash solution for my problem?
source
share