Press spacebar to continue
Here’s a little snippet of Bash code that waits for spacebar to be pressed to continue.
<pre lang="bash">
function spacebar {
echo 'Press spacebar to continue. Press Ctrl-C to exit.'
stty -echo > /dev/null
until read -r -n 1 -t 0.001 && [ "$REPLY" = ' ' ]; do abc=''; done
stty echo > /dev/null
}
echo 'Starting upgrade'
spacebar
Output
<pre lang="bash">
Starting upgrade
Press spacebar to continue. Or Ctrl-C to exit.
If you press spacebar it will continue. Ctrl-C exits the program.