read 选项 变量名
-p "提示信息"
-t 指定等待时间,不指定则一直等待
-n 指定接收的字符数,不指定则不限制
-s 隐藏输入的数据,适用于机密信息的输入
[[email protected] sh]# vi param_test3.sh
[[email protected] sh]# cat param_test3.sh
#!/bin/bash
# 提示用户输入并等待30秒,并将输入结果存入name变量中
read -t 30 -p "Please input you name: " name
echo -e "\n"
echo "Name is $name"
# 加上 -s 以后 输入age的时候将隐藏起来
read -s -t 30 -p "Please input you age: " age
echo -e "\n"
echo "Age is $age"
# -n 1 代表只接收一个字符
read -n 1 -t 30 -p "Please input gender M/F :" gender
echo -e "\n"
echo "Genger is $gender"
[[email protected] sh]# sh param_test3.sh
Please input you name: xiaol
Name is xiaol
Please input you age:
Age is 12
Please input gender M/F :M
Genger is M
[[email protected] sh]#
时间: 2024-10-12 18:36:12