快速学习-Shell读取控制台输入

第8章 read读取控制台输入

1.基本语法

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

参数
变量:指定读取值的变量名
2.案例实操
(1)提示7秒内,读取控制台输入的名称

[atguigu@hadoop101 datas]$ touch read.sh
[atguigu@hadoop101 datas]$ vim read.sh

#!/bin/bash

read -t 7 -p "Enter your name in 7 seconds " NAME
echo $NAME

[atguigu@hadoop101 datas]$ ./read.sh 
Enter your name in 7 seconds xiaoze
xiaoze
发布了1706 篇原创文章 · 获赞 1763 · 访问量 16万+

猜你喜欢

转载自blog.csdn.net/weixin_42528266/article/details/105053330