In zsh :
read -s -k '?Press any key to continue.'
From man zshbuiltins :
-s Do not select characters when reading from the terminal.-k Read only one character.name?prompt The name is omitted, so user input is stored in the REPLY variable (and we ignore it). The first argument contains ? , so the rest of this word is used as a hint about the standard error when the shell is interactive.
To include a new line after the prompt:
read -s -k $'?Press any key to continue.\n'
$'' is explained in QUOTING in man zshmisc .
Finally, the pause function, which accepts an arbitrary prompt in a script that does what the OP asks:
#!/usr/bin/env zsh pause() read -s -k "?$*"$'\n' while true; do echo "print something" pause "pause" done
Rodolfo Carvalho
source share