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