shell - 在等待read时如何不换行输入echo " Please enter your Name:" read key 运行后: Please enter your Name: my name 光标在第二行上,如何停留咱"Please enter your Name:" 后! 在echo " Please enter your Name:"后加c echo " Please enter your Name:c" echo -n " Please enter your Name:" 根据shell不同,有不同的情况,最简单,最有效的办法是 man echo 即然是精贴,就再给它加点料--虽然关联系并不太大! 以下内容转自<永远的unix>,部份备注信息由本人增加。已在sco504下测试过。 #shell下输入字元的例子 echo "Enter a character:" stty raw #设为输入字元方式,有的系统可用stty cbreak stty -echo #设为不回显方式 readchar=`dd if=/dev/tty bs=1 count=1 2>/dev/null` #块大小为1byte,块数1 stty -raw #取消字元输入方式 stty echo #恢复回显方式 echo "The key is:$readchar" |
|