Sometimes it is useful to pause a script until the user is ready to proceed. In Windows Batch scripting, this can be done with the
PAUSE command. In Bash, the same thing can be done using
read with the right parameters:
read -rn1 -p "Press any key to continue"
This command is doing the following:
-rdisables backslash escaping. Without this option, typing only
\will not continue execution.
-n1instructs the command to read only one character.
-p "Press any key..."is the prompt, or message printed to the screen.
Note that, like Batch’s
PAUSE command, some keys which don’t result in a character being typed, like
CAPS LOCK, will not continue execution. Most other keys will work though.