- 能够应用
read
命令一次性给多个变量赋值 read
命令每个单词之间应用空格离开-p
参数: 提示信息:prompt
read -p 'Please enter a Fruit and Animal:' fruit animalecho "fruit is $fruit, animal is $animal"
-n
参数: 限度字符数
n
是 number
的首字母
用 -n
能够限度用户输出的字符串的最大长度(字符数)
read -p 'Please enter your name(5 characters max): ' -n 5 nameecho -e "\nHello $name !"
-t
:限度输出工夫
t
是time
的首字母
-t
参数能够限定用户的输出工夫(以秒为单位)
超过这个工夫,就不读取输出了
#!/bin/bashread -p 'Please enter the name (you have 5 seconds): ' -t 5 nameecho -e "\nyour name is $name.... !"
-s
:暗藏输出内容
-s
是secret
的首字母
#!/bin/bashread -p 'Please enter the password : ' -s passwordecho -e "\npassword is $password.... !"
1.5、