I have a Bash shell script in which I would like to pause execution until the user presses a key. In DOS, this is easily accomplished with the \"pause\" command. Is there a
This function works in both bash and zsh, and ensures I/O to the terminal:
# Prompt for a keypress to continue. Customise prompt with $*
function pause {
>/dev/tty printf '%s' "${*:-Press any key to continue... }"
[[ $ZSH_VERSION ]] && read -krs # Use -u0 to read from STDIN
[[ $BASH_VERSION ]] &&
Put it in your .{ba,z}shrc for Great Justice!