读书人

在shell中,用read,能够读到[TAB]和[EN

发布时间: 2012-03-16 16:34:56 作者: rapoo

在shell中,用read,能够读到[TAB]和[ENTER]键吗?
比如说我想读到tab和enter键时,退出:

while true;do
read -n1 -s " " keypress
if [ "$keypress " = "[tab] " ] || [ "$keypress " = "[enter] " ]; then
break;
fi
echo $keypress

STR_INPUT=${STR_INPUT}${keypress}
done
echo "String you Input is: "\ "$STR_INPUT\ " ". "


=======================================================
当然,以上程序的if..fi部分肯定有问题,我就是不知道怎么读tab和enter键,因为此时,我可能需要处理用户输入的东西.大家有试过吗?

[解决办法]
关注
[解决办法]
bash的话
设置IFS变量为$ '\n '
[ -z $keypress ]判断回车
[ $keypress == $ '\t ' ]判断tab

读书人网 >UNIXLINUX

热点推荐