Search

read timeout in scripting

The command read is used in scripting to accept a value for a variable from the user.

The default operation of read is to wait infinetly for the user to enter a value. This behavour can be changed and read can be made to wait for a specific time only and abort after that.
This can be done by using the option "-t" with read i.e.



This will make read to wait for 5 seconds before aborting.
The script below shows how to use the option.

read_timeout.sh



The above script waits for 5 seconds for the user to enter a value,if the user fails to do so the script will continue to run and throw an error message.

Save it,give it execute permissions and execute it



If we do not enter any value at the read prompt, after 5 seconds we should see the following message.

Output:




6 comments:

  1. The post is absolutely fantastic! Lots of great information and inspiration both of which we all need! Also like to admire the time and effort you put into your blog and detailed information you offer! I will bookmark your blog!
    Scarprin Information

    ReplyDelete
  2. Im glad to have found this post as its such an interesting one! I am always on the lookout for quality posts and articles so i suppose im lucky to have found this! I hope you will be adding more in the future...
    www.fadeplex.com

    ReplyDelete
  3. Well I am so excited that I have found your post because I have been searching for some information on this for almost three hours! You've helped me a lot indeed and by reading this article I have found many new and useful information about this subject!
    we buy houses

    ReplyDelete
  4. It seems that everybody is into this kind of stuff lately. Don’t really understand it though but thanks for trying to explain it. Appreciate you shedding light into this matter. Keep up your work.
    business information

    ReplyDelete
  5. The tech related blog of Linux World is describing about read timeout in scripting. This is term is very essential in the time of operating this Linux Operating System. So admin is perfect for getting praise.
    Drupal

    ReplyDelete

Follow by Email