1. 基本语法

read(选项)(参数)
选项:
-p:指定读取值的提示符;
-t:指定读取时等待的时间(秒)
参数:
变量:指定读取值

2. 案例实操

(1)提示7秒内,读取控制台输入的名称

  1. [root@localhost ~]# touch read.sh
  2. [root@localhost ~]# chmod 777 read.sh
  3. [root@localhost ~]# vim read.sh
  4. #!/bin/bash
  5. read -t 7 -p "在7秒内输入你的名字" NAME
  6. echo $NAME
  7. [root@localhost ~]# ./read.sh
  8. 7秒内输入你的名字abes
  9. abes
  10. # 没在7秒内输入就会自动退出
  11. [root@localhost ~]# ./read.sh
  12. 7秒内输入你的名字