Advertisement
Cogger

wait_4_esc.sh

Jan 14th, 2023
796
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.35 KB | None | 0 0
  1. #!/bin/bash
  2. # example 4: https://linuxhint.com/bash_wait_keypress/
  3. userinput=""
  4. echo "Press ESC key to quit"
  5. # read a single character
  6. while read -r -n1 key
  7. do
  8. # if input == ESC key
  9. if [[ $key == $'\e' ]];
  10. then
  11. break;
  12. fi
  13. # Add the key to the variable which is pressed by the user.
  14. userinput+=$key
  15. done
  16. printf "\nYou have typed : $userinput\n"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement