32 lines
520 B
Markdown
32 lines
520 B
Markdown
|
- 条件为真就进入循环,条件为假就退出循环
|
||
|
- 语法结构
|
||
|
```shell
|
||
|
while 表达式
|
||
|
do
|
||
|
command
|
||
|
done
|
||
|
```
|
||
|
|
||
|
- 与read结合读取文件
|
||
|
```
|
||
|
me@me-EQ59:~/shell_demo/scripts/shell02$ ./while_read.sh
|
||
|
10.0.0.1
|
||
|
123
|
||
|
10.0.0.2
|
||
|
124
|
||
|
10.0.0.3
|
||
|
125
|
||
|
me@me-EQ59:~/shell_demo/scripts/shell02$ cat while_read.sh
|
||
|
#! /bin/env bash
|
||
|
|
||
|
while read ip pass
|
||
|
do
|
||
|
echo $ip
|
||
|
echo $pass
|
||
|
done < ip.txt
|
||
|
me@me-EQ59:~/shell_demo/scripts/shell02$ cat ip.txt
|
||
|
10.0.0.1 123
|
||
|
10.0.0.2 124
|
||
|
10.0.0.3 125
|
||
|
me@me-EQ59:~/shell_demo/scripts/shell02$
|
||
|
```
|