read 命令详解

20 篇文章 0 订阅

      
      语法:
      read [-ers] [-u fd] [-t timeout] [-a aname] [-p prompt] [-n nchars] [-d delim] [name ...]

      One  line  is  read  from the standard input, or from the file descriptor fd supplied as an argument to the -u option, and the first word is assigned to the first name, the
      second word to the second name, and so on, with leftover words and their intervening separators assigned to the last name.  If there are fewer words  read  from  the  input
      stream  than names, the remaining names are assigned empty values.  The characters in IFS are used to split the line into words.  The backslash character (\) may be used to
      remove any special meaning for the next character read and for line continuation.  Options, if supplied, have the following meanings:

      -a aname
    The words are assigned to sequential indices of the array variable aname, starting at 0.  aname is unset before any new values are assigned.   Other  name  arguments
    are ignored.
    //指定一个变量(变量为数组)

      -d delim
    The first character of delim is used to terminate the input line, rather than newline.
    //设定一个标记,结束时输入这个标记的第一个字符即可结束输入。相当于 EOF!
    
      -e     If the standard input is coming from a terminal, readline (see READLINE above) is used to obtain the line.
    //可以按tab键显示当前目录下的文件

      -n nchars
    read returns after reading nchars characters rather than waiting for a complete line of input.
    //指定输入的字符长度,超过此长度自动退出

      -p prompt
    Display  prompt on standard error, without a trailing newline, before attempting to read any input.  The prompt is displayed only if input is coming from a terminal.
    //指定提示信息

      -r     Backslash does not act as an escape character.  The backslash is considered to be part of the line.  In particular, a backslash-newline pair may not  be  used  as  a
    line continuation.
    //禁止反斜杠作为控制字符(转义字符)

      -s     Silent mode.  If input is coming from a terminal, characters are not echoed.
    //静默方式,输入的字符不显示在屏幕上,这个选项一般用于输入密码

      -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.
    //设置等待输入的超时时间,单位为秒,超过此时间自动退出

      -u fd  Read input from file descriptor fd.
    //指定从某个文件描述符读取数据

      If no names are supplied, the line read is assigned to the variable REPLY.  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 -u.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值