read命令读取用户输入

2015-08-31 21:23:05 · 作者: · 浏览: 24

read命令用于从终端或文件中读取用户输入,它读取整行输入,如果没有指定名称,读取的行被赋值给内部变量REPLY。
read命令常用选项:-a,-p,-s,-t,-n


$read
hello
$echo $REPLY
hello


$read answer
hello
$echo $answer
hello


$read first second third
chen xiaopang panda
$echo $first $second $third
chen xiaopang panda


$read -p "Enter your name:" name
Enter your name:chenxiaopang
$echo $name
chenxiaopang


$read -a friends
Tom Mike Jack
$echo ${friends[*]}
Tom Mike Jack


$read -t 5 choice //限定5秒钟内输入变量值,否则,不管用户是否输入,read命令返回非零值


$read -n1 -p 'Enter your Choice (y/n): ' choice
$echo $choice
y


$read -s name


cat test.txt | while read line
do


done?