Bash: timed read input

March 13th, 2007 mysurface Posted in Bash, read | Hits: 54245 | 2 Comments »

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.

2 Responses 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?

  2. ‘This week, I will only drink one beer on Friday night,
    saving myself thousands of calories’. This isn’t the only reason that
    we know Vi – Salus isn’t a scam; the product is real, and it’s backed by real research in nutrition too.
    Well, mainly because it is tricky to differentiate your products and solutions from other providers this sort of
    as Herbalife, Pharmanex, Usana, Noni, or any of the other
    hundreds of herbal supplement Multi level marketing companies about the

Leave a Reply