巧用 read 实现“按任意键继续”

巧用 read 实现“按任意键继续”

以前看过许多帖子,大都用 stty 来实现“press any key to continue”,昨日看 read 的 manual,发现这样也可:
复制内容到剪贴板
代码:
read -s -n1 -p "按任意键继续 ... "
      
复制内容到剪贴板
代码:
read: read [-ers] [-u fd] [-t timeout] [-p prompt] [-a array] [-n nchars] [-d delim] [name ...]
    One line is read from the standard input, or from file descriptor FD if the
   [color=red] -u[/color] option is supplied, and the first word is assigned to the first NAME,
    the second word to the second NAME, and so on, with leftover words assigned
    to the last NAME.  Only the characters found in $IFS are recognized as word
    delimiters.  If no NAMEs are supplied, the line read is stored in the REPLY
    variable.  If the[color=red] -r[/color] option is given, this signifies `raw' input, and
    backslash escaping is disabled.  The[color=red] -d[/color] option causes read to continue
    until the first character of DELIM is read, rather than newline.  If the[color=red] -p[/color]
    option is supplied, the string PROMPT is output without a trailing newline
    before attempting to read.  If[color=red] -a[/color] is supplied, the words read are assigned
    to sequential indices of ARRAY, starting at zero.  If[color=red] -e[/color] is supplied and
    the shell is interactive, readline is used to obtain the line.  If[color=red] -n[/color] is
    supplied with a non-zero NCHARS argument, read returns after NCHARS
    characters have been read.  The[color=red] -s[/color] option causes input coming from a
    terminal to not be echoed.
   
    The[color=red] -t[/color] option causes read to time out and return failure if a complete line
    of input is not read within TIMEOUT seconds.  If the TMOUT variable is set,
    its value is the default timeout.  The return code is zero, unless end-of-file
    is encountered, read times out, or an invalid file descriptor is supplied as
    the argument to[color=red] -u[/color].
      
这个好!正好用上      
太感谢dearvoid,真乃及时雨dearvoid      
晕,我一直都是这么实现“按任意键”继续的,我怀疑方法不正确,还不好意思说。      
唉, 像你这样的高手不多了, 好多人都不知道呢