preSS进入或等待10秒以上 [英] Press enter or wait 10 seconds to continue

查看:302
本文介绍了preSS进入或等待10秒以上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以要求用户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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆