当前位置: 技术问答>linux和unix
在shell中,用read,能够读到[TAB]和[ENTER]键吗?
来源: 互联网 发布时间:2016-01-07
本文导语: 比如说我想读到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_INPU...
比如说我想读到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键,因为此时,我可能需要处理用户输入的东西.大家有试过吗?
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
设置IFS变量为$'n'
[ -z $keypress ]判断回车
[ $keypress == $'t' ]判断tab
|
关注