记录一下。
几个简单参数介绍
read -p :显示提示信息
read -s :静默模式(Silent mode),不会在屏幕上显示输入的字符。当输入密码和其它确认信息的时候,这是很有必要的。
read -t seconds -p :设置超时时间,单位为秒。如果用户没有在指定时间内输入完成,那么将退出输入。
应用示例(read.sh):
#!/bin/bash#author:zhangyl
#输入用户名:rootread -p "请输入用户名: " nameecho "The username is $name."
#输入密码:root@123!echo -n "请输入密码: " #echo -n 表示不换行输出read -s passwdecho ""echo "The passwd input is $passwd."
#输入用户名:rootread -t 5 -p "请输入用户名: " nameecho "The username is $name."
执行结果:
[root@ZWZF-CWY-LZY-12 upload]# vim read.sh
[root@ZWZF-CWY-LZY-12 upload]# sh read.sh
请输入用户名: root
The username is root.
请输入密码:
The passwd input is root@123!.
请输入用户名: The username is . #5秒内没有操作
[root@ZWZF-CWY-LZY-12 upload]#