The easy way is to use the
-t option of
read to specify a timeout in seconds for each input statement. The more complex way is one suggested by the Advanced Bash Scripting Guide, which defines a functions that can be used further through the script and its childs:
Code:
timedout_read() {
timeout=$1
varname=$2
old_tty_settings=`stty -g`
stty -icanon min 0 time ${timeout}0
eval read $varname # or just read $varname
stty "$old_tty_settings"
}
but as you can see its usage is quite the same as
read -t. This function shows the correct global settings, anyway. Reference:
http://www.tldp.org/LDP/abs/html/int...s.html#TIMEOUT