Transferred from: Http://man.linuxde.net/read
Read command
The read command reads the value of a variable from the keyboard and is typically used in a shell script to interact with the user.
The command can read the values of multiple variables at once, and the variables and input values need to be separated by spaces.
After the read command, if no variable name is specified, the read data is automatically assigned to the specific variable reply
Syntax read (option) (parameter) option-P: Specifies the prompt to read the value;
-T: Specifies the time to wait (in seconds) to read the value.
Parameter variable: Specifies the variable name of the Read value.
Instance
The following list shows the common ways of the Read command:
Read 1987name reads input from the standard input and assigns a value to the variable 1987name.
Read first last reads the input from the standard input to the first space or carriage return, puts the input word into the variable, and places the other input into the last variable.
Read reads a row from the standard input and assigns a value to the specific variable reply.
Read-a Arrayname reads the list of words into the arrayname array.
Read-p the "text" Print hint (text), waits for input, and stores the input in reply.
The Read-r line allows the input to contain a backslash.
READ-T 3 Specifies a read wait time of 3 seconds.
Read-n 2 Var reads two characters from the input and stores the variable Var, without having to press ENTER to read.
Read-d ":" Var with delimiter ":" Ends the input line.
The read command example reads input from the standard input and assigns a value to the variable 1987name.
#read 1987name #等待读取输入 until the Enter is complete, and the input is assigned to the variable answer HelloWorld
#控制台输入Hello
#echo $1987name
#打印变量 HelloWorld waits for a set of inputs, separated by a space between each word, until the carriage return ends, and the words are assigned to the three read-in variables, respectively.
#read One and three 1 2 3 #在控制台输入1 2 3, separated by a space.
#echo "one = $one, and the other = $two, three = $three" one = 1, the other = 2, three = 3
Reply Example
#read #等待控制台输入 and assigns the result to a specific built-in variable, reply.
This is REPLY #在控制台输入该行.
#echo $REPLY #打印输出特定内置变量REPLY to confirm that the value was correctly assigned.
This is reply-p option example #read-P "Enter your name:" #输出文本提示 while waiting for input and assigning the result to REPLY.
Enter you Name:stephen
#在提示文本之后输入stephen #echo $REPLY Stephen waits for the console input and treats the input information as an array, assigns the array variable friends, and the input information separates each element of the array with a space.
#read-a Friends Tim Tom Helen #echo "They is ${friends[0]}, ${friends[1]} and ${friends[2]}." They is Tim, Tom and Helen. Add a terminal input password, do not let the password display example.
Method 1: #!/bin/bash read-p "Enter password:"-s pwd echo echo password read, is "$pwd"
Method 2: #!/bin/bash stty-echo read-p "Enter password:" PWD stty echo echo echo input completed. Where option-echo disables sending the output to the terminal, and the option echo allows the output to be sent.
Read the variable value from the keyboard using the Read command, and assign the value to the specified variable, and enter the following command: Read V1 v3
#读取变量值 after executing the above instruction, you are required to type two data as follows: After the Linux c+ #输入数据 is complete, you can use the Echo command to view the specified variable value output and enter the following command: Echo $v 1 $v 3
#输出变量的值 the command that executes the output variable value, the data value entered by the user is displayed as follows: Linux c+ #输出变量值 Note: When you use the echo command to output a variable value, you must add the symbol $ before the variable name. Otherwise, echo will output the variable name directly.
From: http://man.linuxde.net/read
The read command reads the value of a variable from the keyboard and is typically used in a shell script to interact with the user. The command can read the values of multiple variables at once, and the variables and input values need to be separated by spaces. After the read command, if no variable name is specified, the read data is automatically assigned to the specific variable reply
From: Http://man.linuxde.net/readread command reads the value of a variable from the keyboard and is typically used in a shell script to interact with the user. The command can read the values of multiple variables at once, and the variables and input values need to be separated by spaces. After the read command, if no variable name is specified, the read data is automatically assigned to the specific variable reply syntax read (option) (parameter) option-P: Specifies the prompt when the value is read;-T: Specifies the time to wait (in seconds) to read the value. Parameter variable: Specifies the variable name of the Read value. Instance
From: Http://man.linuxde.net/readread command shell built-in command the Read command reads the value of a variable from the keyboard and is typically used in a shell script to interact with the user. The command can read the values of multiple variables at once, and the variables and input values need to be separated by spaces. After the read command, if no variable name is specified, the read data is automatically assigned to the specific variable reply syntax read (option) (parameter) option-P: Specifies the prompt when the value is read;-T: Specifies the time to wait (in seconds) to read the value. Parameter variable: Specifies the variable name of the Read value. The following list of instances gives the common way of the Read command: Read 1987name reads input from the standard input and assigns a value to the variable 1987name. Read first last reads the input from the standard input to the first space or carriage return, puts the input word into the variable, and places the other input into the last variable. Read reads a row from the standard input and assigns a value to the specific variable reply. Read-a Arrayname reads the list of words into the arrayname array. Read-p the "text" Print hint (text), waits for input, and stores the input in reply. The Read-r line allows the input to contain a backslash. READ-T 3 Specifies a read wait time of 3 seconds. Read-n 2 Var reads two characters from the input and stores the variable Var, without having to press ENTER to read. Read-d ":" Var with delimiter ":" Ends the input line. The read command example reads input from the standard input and assigns a value to the variable 1987name. #read 1987name #等待读取输入, until the carriage return indicates that the input is complete, and assigns the input to the variable answer HelloWorld #控制台输入Hello #echo $1987name #打印变量 HelloWorld Wait for a set of inputs, Each word is separated by a space until the carriage return ends, and the words are assigned to the three read variables in turn. #read One and three 1 2 3 #在控制台输入1 2 3, separated by a space. #echo "one = $one, one = $two, three = $three" one = 1, and the three = 3 Reply example #read #等待控制台输入 and assigns the result to a specific built-in variable reply. This is REPLY #在控制台输入该行. #echo $REPLY #打印输出特定内置变量REPLY to confirm that the value is correctly assigned. This is reply-p option example #read-P "Enter your name:" #输出文本提示 while waiting for input and assigning the result to REPLY. Enter you name:stephen #在提示文本之后输入stephen #echo $REPLY Stephen waits for console input and treats the input information as an array, assigns the array variable friends, and the input information separates each element of the array with a space. #read-a Friends Tim Tom Helen #echo "They is ${friends[0]}, ${friends[1]} and ${friends[2]}." They is Tim, Tom and Helen. Add a terminal input password, do not let the password display example. Method 1: #!/bin/bash read-p "Enter password:"-s pwd echo echo password read, is "$pwd" Method 2: #!/bin/bash stty-echo read-p "Enter password:" pwd Stty echo Echo echo input is complete. Where option-echo disables sending the output to the terminal, and the option echo allows the output to be sent. Use the Read command to read the variable value from the keyboard, and assign the value to the specified variable, and enter the following command: Read v1 v3 #读取变量值 after executing the above instruction, you are required to type two data as follows: After the Linux c+ #输入数据 is complete, You can use the Echo command to view the specified variable value output and enter the following command: Echo $v 1 $v 3 #输出变量的值 after the command that executes the output variable value, the data value entered by the user is displayed as follows: Linux c+ #输出变量值 Note: When using the echo command to output variable values, You must add the symbol $ before the variable name. Otherwise, echo will output the variable name directly.
From: Http://man.linuxde.net/read
Linux-read command