linux系统中 while read逐行读取数据

1、测试for  cat

[root@PC3 test]# cat a.txt
01 02 03
06 07 08
11 12 13
16 17 18
[root@PC3 test]# for i in `cat a.txt`; do echo $i ; done
01
02
03
06
07
08
11
12
13
16
17
18

2、测试while  read

[root@PC3 test]# cat a.txt
01 02 03
06 07 08
11 12 13
16 17 18
[root@PC3 test]# cat a.txt | while read i; do echo $i; done
01 02 03
06 07 08
11 12 13
16 17 18

while read  为逐行读取, 可基于此方法在每行传递多个参数。

原文地址:https://www.cnblogs.com/liujiaxin2018/p/14684772.html