Bash: timed read input

March 13th, 2007 mysurface Posted in Bash, read | Hits: 44274 | 1 Comment »

For some critical task, you just can’t wait for user response forever. If the user do not respond to input after certain period of time, you will use the default value and carry on the process. The bash command read have such capability to support that.

A simple example to illustrate how it works

answer="yes";read -p "Are you sure you wanna install now? " -t 10 answer;echo " Your answer is $answer";

-t is to specified seconds to wait, if user do not respond in 10 seconds, the next command will be carry on.

One Response to “Bash: timed read input”

  1. Is it okay to insert part of this in my personal webpage if I publish a reference point to this website?

Leave a Reply