I need a pause on a shell script to show a warning before continuing. For instance, on DOS it goes like this:


echo 'Are you sure? Press Ctrl-C to abort, enter to continue.'

How can I do this on bash? For the moment a sleep command seems to do the trick and is simple enough but is not exactly the idea:


echo 'Are you sure? Press Ctrl-C to abort.'
sleep 3

something along the lines of

echo -n "prompt"  #'-n' means do not add \n to end of string
read              # No arg means dump next line of input
  • 14
    In Bash, this can be shortened to read -p "prompt". More details on shell built-ins can be retrieved with the help command, e.g. help read. – Lekensteyn Feb 27 '12 at 17:32
  • @Lekensteyn - That's without a trailing newline though. – hookenz Mar 15 '12 at 18:36
  • @MattH Just like echo -n and printf. If you press Enter, you will get a newline. – Lekensteyn Mar 15 '12 at 19:54
  • 1
    that does not work for ubuntu 12.04 - read requires argumenst – ses May 14 '14 at 20:09
  • 1
    @ses On 12.04.4 using bash there is no requirement that read have an argument. Using sh (which often invokes bash in sh compatible mode) read requires an argument. If you start your script with #!/bin/sh you will see the latter behavior – Huckle May 15 '14 at 1:33

read -p "Press any key to continue or CTRL-C to abort" works fine under 14.04 in my scripts. As @Lekensteyn stated in the comment above it seems this has been the case since 12.04.4. The 'help read' page states:

-p prompt   output the string PROMPT without a trailing newline before
            attempting to read

My favourite use of this is to set a default timeout, so that the script can also run unattended:

echo "Press any key to continue..."
read -n1 -t5 any_key


  • -n1 tells the read to accept any single character
  • -t5 tells it to wait a maximum of 5 seconds for input

I work almost exclusively with Bash under CentOS, so I can't vouch for this working on other Linux variants, but since it's Bash, I would expect it to work. I'd love to know for certain if it does! :)


The simples wait to stop the script is to call kill -STOP $$ from the script: After paused the script will continue its work after receiving -CONT signal.

echo "$0 stopping now"
kill -STOP $$
echo "$0 continues its work"
  • How does one send the CONT signal to the script? – David Foerster Dec 31 '15 at 12:00
echo "press enter to continue"
read unusedVariable
echo "running these 3 lines in .sh file, this echo will never be seen, unless you have a really slow computer"

place these 3 lines in a .sh file and run it

  • 1
    -1 What is this supposed to do and why? Why would the output of the last echo command not show up and what does it have to do with the speed of the computer? – David Foerster Dec 31 '15 at 12:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.