read a single pushed key by a dash script

Ralf Mardorf silver.bullet at
Sun Nov 6 18:32:03 UTC 2016

On Sun, 06 Nov 2016 16:59:46 +0100, Oliver Grawert wrote:
>stty -icanon -echo
>REPLY=$(dd bs=1 count=1 2> /dev/null)
>stty icanon echo

Thank you,

I'm uncertain if stty is more neat, than simply using bash's read. I
had in mind, that it could cause issues, but indeed, your suggestion
seems to work without issues.

ubuntu-mate at ubuntu-mate:~$ cat /tmp/ 

for i in 1 2 3; do
  stty -icanon -echo
  REPLY=$(dd bs=1 count=1 2> /dev/null)
  stty icanon echo
  echo $REPLY

for i in 1 2 3; do
  bash -c "read -n1 answer"
  echo $answer



More information about the ubuntu-users mailing list