read 命令从标准输入中读取一行,并把输入行的每个字段的值指定给 shell 变量
-p read –p “提示语句”,则屏幕就会输出提示语句,等待输入,并将输入存储在REPLY中
-n read –n 个数
-t read –t 时间
-s read -s 选项能够使read命令中输入的数据不显示在监视器上
[xiess@layzj022301 ~]$ read readfile
hello,world!!welcome to shell
[xiess@layzj022301 ~]$ echo $readfile
hello,world!!welcome to shell
[xiess@layzj022301 ~]$
[xiess@layzj022301 ~]$ read frist second third
the_one the_two the_three
[xiess@layzj022301 ~]$ echo "$frist" "$second" "$third"
the_one the_two the_three
[xiess@layzj022301 ~]$
[xiess@layzj022301 ~]$ read -p "Enter your name: "
Enter your name: admin_xiess
[xiess@layzj022301 ~]$ echo $REPLY
admin_xiess
[xiess@layzj022301 ~]$
[root@cinder01 ~]# cat readfile.sh
#!/bin/bash
read -s -p "Enter your password: " password
echo
echo "your password is $password"
[root@cinder01 ~]# chmod a+x readfile.sh
[root@cinder01 ~]# sh readfile.sh
Enter your password:
your password is 123456
原文:http://www.cnblogs.com/xieshengsen/p/6666972.html