一:read 读取控制台输入

1.1 基本语法

  • read (选项) (参数)

  • ①选项:

    • -p:指定读取值时的提示符;
    • -t:指定读取值时等待的时间(秒)如果-t 不加表示一直等待
  • ②参数:

    • 变量:指定读取值的变量名

1.2 案例实操

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@hadoop100 shell]# cat while.sh 
#!/bin/bash
i=0
sum=0
while [ $i -le 100 ]
do
#sum=$[$sum+$i]
#i=$[$i+1]
let sum+=i
let i++
done
echo $sum
[root@hadoop100 shell]# ./read.sh
请在10秒内输入参数: Ghost
welcome Ghost