• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

spacebar

Bash Spacebar Break

August 16, 2022

Here’s how to add breaks in your Bash scripts. The function is called spacebar.

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
}
 
spacebar

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 } spacebar

You can call it multiple times in your script since it’s a function.

Filed Under: Linux Tagged With: bash, continue, hit, spacebar

Press spacebar to continue

August 5, 2022

Here’s a little snippet of Bash code that waits for spacebar to be pressed to continue.

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

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

Starting upgrade
Press spacebar to continue. Or Ctrl-C to exit.

Starting upgrade Press spacebar to continue. Or Ctrl-C to exit.

If you press spacebar it will continue. Ctrl-C exits the program.

Filed Under: Linux Tagged With: bash, continue, spacebar, wait

  • Home
  • About
  • Archives

Copyright © 2023