To interact with Linux, the script gets keyboard input results that are essential, and read can read the keyboard input characters.
1. Restricting input characters
For example, after you enter 5 characters, you end up with 5 characters entered into the variable. In other words, rely on the number of characters entered as the end flag.
Read-n num var: the input num characters are stored in variable var.
[[email protected] tmp]# Read-n 5 var
12345[[email protected] tmp]# echo $var ? Input 12345 A total of 5 characters
12345
2. Do not echo the input characters
For example, when entering a password, do not echo the password entered.
read-s var: the input character is stored in var. After entering, press ENTER to finish.
[email protected] tmp]# read-s var ? Enter 987654 here
[Email protected] tmp]# echo $var
987654
3. Give the input hint
Use the-P option.
[Email protected] tmp]# read-p "Please input your name:" var
Please input your name:myname
[Email protected] tmp]# echo $var
MyName
4. Give the input time limit
Automatically end without input in a few seconds, or enter a part to the limit time to end automatically, the input initialization variable is not completed, that is, discard the result and let the variable be called the Unassigned State.
[Email protected] tmp]# read-t 5-p "Please input your name in three seconds:" Var
5. Give the end delimiter
The character before the input delimiter is stored in the variable.
[Email protected] tmp]# read-d "," var
Jinse,[[email protected] tmp]# echo $var
Jinse
Shell Script Raiders (learning note)--1.12 Read basics