Skip to content

第十八章:read 读取控制台输入 ​

  • 基本语法
shell
read (选项) (参数)
	1. 选项:
		-p:执行读取值时的提示符
		-t:指定读取值时等待的时间(秒)如果 -t 不加表示一直等待
	2. 参数:
		变量:指定读取值的变量名
  • 案例实操

    • 提示 10 秒内,读取控制台输入的名称
    shell
    #!/bin/bash
    read -t 10 -p "请输入你的芳名:" name
    echo "welome $name"

    image-20220705161918918

Released under the MIT License.