Linux中read接收用户输入

来源:互联网 发布:淘宝 clarks小公主 编辑:程序博客网 时间:2024/05/18 01:49
#!/bin/bash

#提示Please input your name并等待20秒,把输入内容存入变量name中
read -t 20 -p "Please input your name: " name
echo "input name is $name"


#-s选项隐藏输入,用于隐藏项
read -s -t 20 -p "Please enter your password: " pwd
echo -e "\n"
echo "input password is $pwd"


#-n 1表示只接收一个输入字符就会执行,不需要输入回车
read -n 1 -t 20 -p "Please input your gender[M/F]:" gender
echo -e "\n"
echo "input gender is $gender"

1 0