Linux中接收键盘输入

read 选项 变量名
  -p    "提示信息"
  -t     指定等待时间,不指定则一直等待
  -n    指定接收的字符数,不指定则不限制
  -s    隐藏输入的数据,适用于机密信息的输入

[root@localhost sh]# vi param_test3.sh
[root@localhost 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"

[root@localhost 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
[root@localhost sh]#

posted @ 2017-07-11 23:30  413Xiaol  阅读(3695)  评论(0编辑  收藏  举报