What is the bash equivalent of DOS's pause command?
I need a pause on a shell script to show a warning before continuing. For instance, on DOS it goes like this:
doit.bat:
[...]
echo 'Are you sure? Press Ctrl-C to abort, enter to continue.'
pause
[...]
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:
doit.sh
[...]
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
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
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.
#!/bin/bash
echo "$0 stopping now"
kill -STOP $$
echo "$0 continues its work"