I want to detect a single key by a script and found two possible solutions (e.g. with key = "z"):
Code: Select all
char=''
read -n1 char > /dev/null
if [ "$char" = "z" ] ; then
...
fi
Code: Select all
stty raw -echo
char=`dd bs=1 count=1 2>/dev/null`
if [ "$char" = "z" ] ; then
...
fi
stty -raw echo
So, is it a problem of maybe I/O redirection or am I barking up the wrong tree?
hopefully,
Rolf