语法:
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.
read 命令详解
最新推荐文章于 2024-05-11 23:27:46 发布