Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

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
share|improve this question

4 Answers 4

up vote 6 down vote accepted

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
share|improve this answer
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. – Matt H 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
that does not work for ubuntu 12.04 - read requires argumenst – ses May 14 '14 at 20:09
@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
share|improve this answer

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"
share|improve this answer
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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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