基本语法语义
read [选项]|[参数]
选项
-p:指定读取值时的提示符
-t:指定读取值时等待的时间(秒)
参数
变量:指定读取值的变量名
实际演示:
脚本内容
root@wordpress ~# cat read.sh
#!/bin/sh
echo Input value in 10 seconds
read -p "Enter options:" -t 10 options # 后面的options为变量
echo This is the option you entered: $options
执行
root@wordpress ~# bash read.sh
Input value in 10 seconds
Enter options:10
This is the option you entered 10
root@wordpress ~#
一句话的脚本
root@wordpress ~# echo Input value in 10 seconds && read -p "Enter options:" -t 10 options && echo This is the option you entered: $options
Input value in 10 seconds
Enter options:10
This is the option you entered 10
root@wordpress ~#
Comments | NOTHING