Read command: Primarily used in the shell to read input, variables, text
1. accept input from the standard input (keyboard) and assign the input data to the SET variable
"Press Enter--indicates that the input is complete"
"If more data is entered than the number of variables set, the extra portion is assigned to the last variable"
"If the variable is not set, the input data is assigned to the environment variable replay"
#!/bin/bashecho"Enter your name:"read name1 name2Echo Hello, $name 1, $name. /read. SH Enter your Name:taeyeon jessicahello,taeyeon,jessica
2.- p print a prompt directly in the Read command line
#!/bin/bashread -P "Enter your name:" name1 name2 echo Hello, $name 1, $name. /read. SH Enter your Name:taeyeon jessicahello,taeyeon,jessica
3.-T implements timing input. Specifies the number of seconds that the read command waits for input.
#!/bin/BashifRead-t5-P"Enter your name:"Name # #-after p to direct the prompt, pay attention to multi-option how to use Then EchoHello, $nameElse Echo-E"\nsorry,too Slow"fiExit0# ./read.SHEnter your name:jellyhello,jelly#./read.SHEnter your Name:sorry,too slow
4.-N implements the count input. Specifies that the read command accepts the input data length. When this length is exceeded, either pressing any key indicates the end of the input.
-n1 indicates that the input of a character is accepted and exits without pressing the ENTER key
#!/bin/Bashread-n1-p"want to continue [y/n]?"Y1 Case$y 1inchY|y)Echo-E"\nok,continue!";; N|n)Echo-E"\nok,stop!";; *)Echo-E"\nerror choice!"Esac# ./read.SHwant to continue [y/n]?yok,continue!# ./read.SHwant to continue [y/n]?Nok,stop!# ./read.SHwant to continue [y/n]?perror Choice!
5.-S implements hidden input. The actual result is that the input data is consistent with the background color. Often used to accept password input.
#!/bin/-S "Enter you password:"passwdecho" \ n " Echo " haha,your passwd is: $passwd " ~]#./read. SH Enter you password: passwd is:aixocm
6. Read the data in the text as input to read
#!/bin/Bashcount=1cat gg.txt while Read name # Reads the contents of the Gg.txt text row by line to the variable namedo echo"$count: $name" Count=$[$count +1]done#. /read. SH 1 : Taeyeon 2 : Jessica 3: Sunny
[Shell Foundation]--read Command