typora/note/Shell/while 循环语法.md
2024-12-12 10:48:55 +08:00

520 B

  • 条件为真就进入循环,条件为假就退出循环
  • 语法结构
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$