isFirst=1
while true; do
_tty_setting=$(stty -g)
stty -icanon
if [ "$isFirst" != "1" ]; then
_key_press=`read -t 5 a; echo $a`
else
_key_press=1
isFirst=0
fi
if [ "$_key_press" != "" ];then
key_save=$_key_press
else
_key_press=$key_save
fi
stty $_tty_setting
case $_key_press in
1) clear;showDetail
;;
2) clear;showDifferent
;;
3) clear;showMissing
;;
4) clear;showWaiting
;;
5) clear;showSame
;;
6) echo ""
echo "bye."
exit 0
;;
esac
done
关于
stty -icanon
read -t 5 a; echo $a
key_save=$_key_press
这几个地方看不懂
这段代码究竟要实现什么功能?具体能解释下吗
stty -icanon
å
³é驱å¨ç¨åºä¸çè§è模å¼å¤çï¼è·³è¿ç¼å²å±,ç¨æ·ä¸è½å é¤å符
read -t 5 a; echo $a å°å±å¹è¾å
¥æ¾å¨åéaä¸ï¼ç¶åè¾åºï¼èµå¼ç» _key_press
大è´æ³¨éäºä¸ä¸ï¼
sFirst=1 #æ è®°while true; do #æ é循ç¯
_tty_setting=$(stty -g) #å° stty设置ä¿åå¨_tty_setting
stty -icanon #å ³é驱å¨ç¨åºä¸çè§è模å¼å¤çï¼è·³è¿ç¼å²å±,ç¨æ·ä¸è½å é¤å符
if [ "$isFirst" != "1" ]; then #å¨è¿ä¸ªæ è®°ä¸éè¦è¯»åè¾å ¥
_key_press=`read -t 5 a; echo $a` #å°å±å¹è¾å ¥æ¾å¨åéaä¸ï¼ç¶åè¾åºï¼èµå¼ç» _key_press
else
_key_press=1 #å¦ä¸ä¸ªåæ¯
isFirst=0
fi
if [ "$_key_press" != "" ];then #æè¾å ¥ä¸è¥¿
key_save=$_key_press #æ¾å¨key_saveä¸
else
_key_press=$key_save #没æè¾å ¥ï¼æ¾ä¸æ¬¡çä¸è¥¿
fi
stty $_tty_setting #æ¢å¤stty设置
case $_key_press in #æ ¹æ®ä¸åçä¸è¥¿ï¼å¤çä¸åé»è¾
1) clear;showDetail
;;
2) clear;showDifferent
;;
3) clear;showMissing
;;
4) clear;showWaiting
;;
5) clear;showSame
;;
6) echo ""
echo "bye."
exit 0
;;
esac
done