read command with timeout for non-terminal input in bash
The read command in bash is used for user input. Option -t N invokes the timeout of N seconds. But, as mentioned in the man page,
This option has no effect if read is not reading input from the terminal or from a pipe.
But this is exactly what I need - I need a script that is launched via desktop shortcut (not from terminal), and should wait another second for a single key to decide further actions. How can I make bash script wait a bit for user input in this case?
11 Answer
Use timeout command before the read command.
Syntax:timeout [OPTION] NUMBER[SUFFIX] COMMAND [ARG]...