Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7558369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:21:15+00:00 2026-05-30T12:21:15+00:00

I can ask the user to press Enter by using read , and have

  • 0

I can ask the user to press Enter by using read, and have him wait by calling sleep. But I can’t think of a way of doing both at the same time. I would like the user to be given the choice:

Press Ctrl+C to Cancel, Enter to continue or just wait 10 seconds

How can I do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T12:21:17+00:00Added an answer on May 30, 2026 at 12:21 pm

    In bash(1), the read command has a -t option where you can specify a timeout. From the man page:

    read [-ers] [-u fd] [-t timeout] [-a aname] [-p prompt] [-n nchars] [-d delim] [name ...]

    -t timeout: cause read to time out and return failure if a complete line of input is not read within timeout seconds. This option has no effect if read is not reading input from the terminal or a pipe.

    Transcript below (without hitting ENTER):

    $ date ; read -t 10 -p "Hit ENTER or wait ten seconds" ; echo ; date
    Tue Feb 28 22:29:15 WAST 2012
    Hit ENTER or wait ten seconds
    Tue Feb 28 22:29:25 WAST 2012
    

    Another, hitting ENTER after a couple of seconds:

    $ date ; read -t 10 -p "Hit ENTER or wait ten seconds" ; date
    Tue Feb 28 22:30:17 WAST 2012
    Hit ENTER or wait ten seconds
    Tue Feb 28 22:30:19 WAST 2012
    

    And a final one, hitting CTRL-C:

    $ date ; read -t 10 -p "Hit ENTER or wait ten seconds" ; echo ; date
    Tue Feb 28 22:30:29 WAST 2012
    Hit ENTER or wait ten seconds
    

    (1) If you’re doing this in a script, make sure that it’s running under bash rather than some other shell.

    You can do that in many ways such as by using a #! shebang line of some type, specifying the shell when you run the command, or making sure your system will run bash by default for scripts.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't think this can be done cleanly, but I'll ask anyway. I have
The best way I can think of to ask this is by example... In
I have multiple instances of the same application running. The user ask can click
On my web site a have a page where where user can ask questions.
Is there a way I can ask Visual source safe to get all the
im new with regexp, so can i ask for some assistance Using string.replace function
I want to ask how can someone read keystrokes while in a html page
You can read this question where I ask about the best architecture for a
Can I disable right click on my web page without using JavaScript? I ask
i am using vb.net i just wanna ask if we can place a picture

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.