| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | # timeout.sh |
| 3 | |
| 4 | # Written by Stephane Chazelas, |
| 5 | #+ and modified by the document author. |
| 6 | |
| 7 | INTERVAL=5 # timeout interval |
| 8 | |
| 9 | timedout_readscip-shell shell abs-guide 10-4 timedout_read().() { |
| 10 | timeout=$1 |
| 11 | varname=$2 |
| 12 | old_tty_settings=`sttyscip-shell system . . stty. -g` |
| 13 | sttyscip-shell system . . stty. -icanon min 0 time ${timeout}0 |
| 14 | eval read $varname # or just read $varname |
| 15 | sttyscip-shell system . . stty. "$old_tty_settings" |
| 16 | # See man page for "stty." |
| 17 | } |
| 18 | |
| 19 | echoscip-shell system . . echo.; echoscip-shell system . . echo. -n "What's your name? Quick! " |
| 20 | timedout_readscip-shell shell abs-guide 10-4 timedout_read(). $INTERVAL your_name |
| 21 | |
| 22 | # This may not work on every terminal type. |
| 23 | # The maximum timeout depends on the terminal. |
| 24 | #+ (it is often 25.5 seconds). |
| 25 | |
| 26 | echoscip-shell system . . echo. |
| 27 | |
| 28 | if [scip-shell system . . `[`. ! -z "$your_name" ] # If name input before timeout ... |
| 29 | then |
| 30 | echoscip-shell system . . echo. "Your name is $your_name." |
| 31 | else |
| 32 | echoscip-shell system . . echo. "Timed out." |
| 33 | fi |
| 34 | |
| 35 | echoscip-shell system . . echo. |
| 36 | |
| 37 | # The behavior of this script differs somewhat from "timed-input.sh." |
| 38 | # At each keystroke, the counter resets. |
| 39 | |
| 40 | exit 0 |