How to get keystrokes in a bash terminal on MacOS?
I found the code here (author:Chris Redford): enter link description here
How to add ESC key to exit loop? Thank you for your help
Modified code:
#!/bin/bash
ESC=$'\033'
# distinguish between enter and space
IFS=''
while true; do
read -rsn1 a
# is the first character ESC?
if [[ $ESC == $a ]]; then
read -rsn2 b
fi
input=$a$b
unset b
case $input in
$ESC[A) echo UP ;;
$ESC[B) echo DOWN ;;
$ESC[C) echo RIGHT ;;
$ESC[D) echo LEFT ;;
$ESC) break ;; ### This line does not work ###
'') echo ENTER ;;
q) break ;;
esac
done