read
Text: 523066680
First one today.
It can be regarded as a kind of note, just like a log
Not really sharing, because everyone will go through their own exploration process.
By the way, learn English, so I pull up the original help together
Parameters and corresponding examples:
-a array assign the words read to sequential indices of the array
variable ARRAY, starting at zero
Assign the input content to the sequential indices of the array according to the delimiter (space or tab, etc.), and consecutive spaces are also counted as 1 division.
After input, the array specification is the same as in C language, and it is expressed in the format of var, with subscripts starting from 0.
Directly echo $var is equivalent to echo ${var}
When echoing an array with subscripts, remember to add {} to express, for example, echo ${a}
Define array variable: read -a arr is okay; read -a arr is wrong.
But you can directly read arr, which is to directly assign a certain element of the array.
-d delim continue until the first character of DELIM is read, rather
than newline
That is, read input until the first character of DELIM is read, instead of ending with a newline. Of course, the "certain character" is not counted.
Test results:
1. After specifying a certain character, the carriage return is also read in, and it will not end due to the carriage return
(Hehe, I haven't tried to end with the carriage return character, I won't make + redundant)
2. -dstr does not reach the end of str, it is the end of s, so people say it is a character
3. -dx str ;# Turned n lines + input character ; echo $str will not output the newline
To echo "$str" will output the newline.
(The following are directly quoted from the help content if I don't know)
-e use Readline to obtain the line in an interactive shell
I don't know, it seems that the default is to end after reading a line? I will make up for it later when I know.
-i text Use TEXT as the initial text for Readline
-n nchars return after reading NCHARS characters rather than waiting
for a newline
rather than here means: instead of.
Read until the Nth character and then end~ instead of waiting for a new line.
The result is that pressing Enter will end in advance
I feel that the description is not strict. The actual rule is {If newline || the number of characters is n; then end}
(The help of this parameter once made me think that rather than means or)
-p prompt prompt is the meaning of prompt, that is, first display the "prompt" string, and then wait for you to input.
With the prompt option, there is no need to echo the prompt separately.
-r do not allow backslashes to escape any characters
backslash backslash "\";
escape escape; here means: escape
Translation: Do not allow backslashes to escape any characters.
-s do not echo input coming from a terminal
Do not display the characters being input from the terminal. (Just like when entering a password),
To be honest, I can't imagine the connection between -s and this function. Learning it is like reciting.
-t timeout time out and return failure if a complete line of input is
not read withint TIMEOUT seconds. The value of the TMOUT
variable is the default timeout. TIMEOUT may be a
fractional number. If TIMEOUT is 0, read returns success only
if input is available on the specified file descriptor. The
exit status is greater than 128 if the timeout is exceeded
1. If a line of input is not completed (triggering the termination input condition) within timeout seconds, it will time out and exit + the command will return an
error code.
2. I can't see this sentence, but executing TMOUT=1, the command line exits after 1 second
3. The value of timeout can be a fractional number , of course, it is not really expressed in fractional notation
It is to tell you that you can use a non-integer, such as -t0.5 is to limit input within half a second.
4. If timeout is set to 0, it will only return success if input is available from the effective special file descriptor.
5. exceed exceed; if timed out, the exit status is greater than 128.
-u fd read from file descriptor FD instead of the standard input
I won't say, I don't know what fd is. Relevant information:
http://baike.baidu.com/view/1303430.htm
"Under linux, all operations are on files, and the operations on files are realized by using file descriptors
(file descriptor). In the source code, fd is generally used as the identifier of the file descriptor."
# Still don't know the meanings of several parameters, so I will come back to modify them when I know... #
End: If read is not followed by a variable name, the value will be assigned to the REPLY variable,
However, if you give a new variable name, REPLY will not be updated synchronously.
+++++++++++++++++Learn some English+++++++++++++
#1 -e use Readline to obtain the line in an interactive shell
Baidu search:
obtain obtain; get
Example: He failed to obtain a scholarship. He didn't get a scholarship.
interactive interactive; interactive
#2 -n nchars return after reading NCHARS characters rather than waiting
for a newline
rather than : instead of
#3 -t timeout
time out and return if a complete line of input is
not read withint TIMEOUT seconds. The value of the TMOUT
variable is the default timeout. TIMEOUT may be a
number. If TIMEOUT is 0, read returns success only
if input is available on the specified file descriptor. The
exit status is greater than 128 if the timeout is
failure n. failure
He was doomed to failure. He was doomed to failure
fractional adjective: small amount; fractional
exceed exceed