read usage operation

read usage operation

1) read reads the command line input parameters -p reads the parameters after displaying a line of text
[root@linhexiao shellTest]# read -p "pls input a number:" var
pls input a number:linhexiao
[root@linhexiao shellTest]# echo $var
linhexiao
2) -t 3 means the input is invalid after 3 seconds
[root@linhexiao shellTest]# read -t 3 -p "pls input a number:" var
pls input a number:[root@linhexiao shellTest]#
3) Multiple parameters can be entered after read
[root@linhexiao shellTest]# read -t 30 -p "pls input two number:" a1 a2
pls input two number:23 34
[root@linhexiao shellTest]# echo $a1 $a2
23 34
4) The above code can be implemented using echo -n ""; read -t
[root@linhexiao shellTest]# echo -n "please input town number:";read -t 30 a1 a2
please input town number:23 45
[root@linhexiao shellTest]# echo $a1 $a2
23 45

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326668987&siteId=291194637
Recommended