read命令顾名思义,就是读取标准输入字符,并赋值给变量。
#!/bin/bash
echo -n "Please input words:"
read input
echo $input
1、-p 选项:显示提示符。
#!/bin/bash
read -p "Please input words:" input
echo $input
2、-t 选项:设定输入等待时间,单位为秒。
#!/bin/bash
if read -t 5 -p "Please your name:" input
then
echo "your name is $input"
else
echo "sorry,timeout"
fi
3、-n 选项:限定输入字符数。
#!/bin/bash
read -n1 -p "Please input y / n:" input
echo $input
4、-s 选项:不显示输入内容。
#!/bin/bash
read -s -p "Pleass password:" input
echo "Your password is $input"