read a single pushed key by a dash script
Ralf Mardorf
silver.bullet at zoho.com
Sun Nov 6 18:53:16 UTC 2016
Maybe I'll use something like this:
ubuntu-mate at ubuntu-mate:~$ cat /tmp/test.sh
#!/bin/dash
# http://stackoverflow.com/questions/8725925/how-to-read-just-a-single-character-in-shell-script
read_p_n() {
printf "$1"
stty -icanon -echo
eval "$3=\$(dd bs=1 count=$2 2>/dev/null)"
stty icanon echo
echo
}
read_p_n "yes or no? " 1 answer
read_p_n "hello " 5 reply
printf "\n$answer $reply\n"
exit
But perhaps I stay with 'bash -c'.
Regards,
Ralf
More information about the ubuntu-users
mailing list