Emulating the DOS Pause Command
Problem
You are migrating from DOS/Windows batch files and want to emulate the DOS
pause
command.
Solution
To do that, use the read -p
command in a function:
pause () { read -p 'Press any key when ready...' }
Discussion
The -p
option followed by a
string argument prints the string before reading input. In this case the
string is the same as the DOS pause
command’s output.
See Also
help read
Get bash Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.