1、用户自定义变量
不加选项:
[root@server1 shells]# read name
kongy
[root@server1 shells]# echo $name
kongy
-p
[root@server1 shells]# read -p "input your name" name
input your namekongying
[root@server1 shells]# echo $name
kongying
-s
[root@server1 shells]# read -s -p "passwd:" mima
passwd:
[root@server1 shells]# echo $mima
westos
-n
没有超出输入规定长度:
[root@server1 shells]# read -n 2 -p "input your age:" age
input your age:34
[root@server1 shells]# echo $age
34
超出规定的输入长度时:
直接卡到那个长度时立即退出输入模式,不给你多输入的机会。
-t
在规定时间内未完成输入就自动退出。
2、变量值来自文件
利用管道符号将文件中的IP地址存入定义的变量IP中。
[root@server1 shells]# vim ip.txt
[root@server1 shells]# read -p "input ip:" IP < ip.txt
[root@server1 shells]# echo $IP
192.168.13.125