linux 中while循环中从文件中读取变量

发布时间 2023-09-12 23:59:19作者: 小鲨鱼2018

 

001、

[root@pc1 test02]# ls
a.txt
[root@pc1 test02]# cat a.txt    ## 测试文件
01 02 03 04
05 06 07 08
09 10 11 12
13 14 15 16
17 18 19 20
[root@pc1 test02]# cat a.txt | while IFS= read i; do echo $i; done    ## 一种方式
01 02 03 04
05 06 07 08
09 10 11 12
13 14 15 16
17 18 19 20
[root@pc1 test02]# while IFS= read i; do echo $i; done < a.txt        ## 二种方式
01 02 03 04
05 06 07 08
09 10 11 12
13 14 15 16
17 18 19 20