preSS进入或等待10秒以上 [英] Press enter or wait 10 seconds to continue
问题描述
我可以要求用户preSS <大骨节病>输入骨节病>使用读
,并通过告诉他等待睡眠
。但我想不出在同一时间做两者的方法。我希望用户给予的选择:
I can ask the user to press Enter by using read
, and have him wait by calling sleep
. But I can’t think of a way of doing both at the same time. I would like the user to be given the choice:
的 preSS <大骨节病>控制骨节病> + <大骨节病> C 骨节病>来取消,<大骨节病>输入骨节病>继续或只是等待10秒钟的
Press Ctrl+C to Cancel, Enter to continue or just wait 10 seconds
我怎么能这样做?
推荐答案
在庆典
,读
有一个 -t
选项,你可以指定一个超时。从手册页:
In bash
, read
has a -t
option where you can specify a timeout. From the manpage:
阅读[-ers] [-u FD] [-t超时] [-a aname] [-p提示] [-n nchars] [-d DELIM] [名称...]
-t超时:
事业读超时,如果输入一个完整的行不超时秒内读取返回失败。该选项如果读没有从终端或管道读取输入没有影响
-t timeout:
cause read to time out and return failure if a complete line of input is not read within timeout seconds. This option has no effect if read is not reading input from the terminal or a pipe.
下面成绩单(不用敲回车):
Transcript below (without hitting ENTER):
$ date ; read -t 10 -p "Hit ENTER or wait ten seconds" ; echo ; date
Tue Feb 28 22:29:15 WAST 2012
Hit ENTER or wait ten seconds
Tue Feb 28 22:29:25 WAST 2012
另外,创下了几秒钟之后按Enter:
Another, hitting ENTER after a couple of seconds:
$ date ; read -t 10 -p "Hit ENTER or wait ten seconds" ; date
Tue Feb 28 22:30:17 WAST 2012
Hit ENTER or wait ten seconds
Tue Feb 28 22:30:19 WAST 2012
和另一个,按CTRL-C
And another, hitting CTRL-C:
$ date ; read -t 10 -p "Hit ENTER or wait ten seconds" ; echo ; date
Tue Feb 28 22:30:29 WAST 2012
Hit ENTER or wait ten seconds
这篇关于preSS进入或等待10秒以上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!