How to read just a single character in shell script
问题 I want similar option like getche() in C. How can I read just a single character input from command line? Using read command can we do it? 回答1: In ksh you can basically do: stty raw REPLY=$(dd bs=1 count=1 2> /dev/null) stty -raw 回答2: In bash, read can do it: read -n1 ans 回答3: read -n1 works for bash The stty raw mode prevents ctrl-c from working and can get you stuck in an input loop with no way out. Also the man page says stty -raw is not guaranteed to return your terminal to the same state