shell实现按任意键继续

shell实现按任意键继续

时间:2013-08-24 12:08:07      作者:admin      标签: Linux shell stty      分类: Linux基础 Shell

有一个数据库,我需要开发一个工具,由于这个数据库没有任何说明,我也不知道当时是怎么创建的。哎,需要找表,找字段,别说有多痛苦了......当然,我是根据数据来找的。我一个个数据表打开看感觉太慢慢,全部打开又会影响到其它工具使用。后来我就了个按任意键继续,没有找到就继续找。具体方法:

!/bin/bash

get_char() { SAVEDSTTY=stty -g      #记录当前stty配置 stty -echo                       #隐藏输入的字符 stty raw dd if=/dev/tty bs=1 count=1 2> /dev/null        #每次只接收一个字符 stty -raw stty echo stty $SAVEDSTTY } for i in mysql -h192.168.0.104 -ugzsy -p123456 gzsy -e "show tables;" |sed 's/[^a-z]//g'; do mysql -h192.168.0.104 -ugzsy -p123456 gzsy -e "select * from $i order by idRecord desc limit 2\G"; echo $i============================================================================= c=get_char if [ "$c" = "q" ];then      #当输入q时就退出 exit 1 fi done

这个例子主要是学习stty,stty的学习资料

stty(settty,设置tty)命令用于检查和修改当前注册的终端的通信参数。UNIX系统为键盘的输入和终端的输出提供了重要的控制手段,可以通过stty命令对特定终端或通信线路设置选项。

可以在stty命令中使用-a查看当前注册终端的设置情况。

[root@server1 bin]# stty -a      speed 38400 baud; rows 33; columns 132; line = 0; intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0; -parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts -cdtrdsr -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8 opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke

这里^表示是ctrl,如intr表示中断,ctrl+C,有时候是不是不小心按了ctrl+s(学习windows时时要保存留下来的习惯),按了之后导致session停了,无法使用。不知道的人就直接关闭终端,重新开了。重新开很麻烦有木有?看到上面的显示了吧

stop = ^S;  表示stop,停止,那么需要再次使用呢?start = ^Q;就是Ctrl+q。

在stty中相应选项前冠以负号(-),该选项被清除(禁止);如果无负号,该选项被设置。

具体stty资料请参考:http://study.chyangwa.com/IT/AIX/aixcmds5/stty.htm#jdfli96manu

时间:2013-08-24 12:08:07      作者:admin      标签: Linux shell stty      分类: Linux基础 Shell
  • 分享到:
  • 微博
  • QQ空间
  • 腾讯微博
  • 微信

Copyright © 2015 Gitblog | Proudly powered by Gitblog.