SHELL 读取文件的每一行内容并filterchain输出
[导读]:假设读取的文件为当期目录下的 test.txt 文件,内容如下: Google RunoobTaobao 实例 1 #!/bin/bash while read line do echo $line done test.txt 执行输出结果为: GoogleRunoobTaobao 实例 2 #!/bin/bash cat...
假设读取的文件为当期目录下的 test.txt 文件,内容如下:
Google Runoob Taobao
实例 1
#!/bin/bashwhile read line
do
echo $line
done < test.txt
执行输出结果为:
Google Runoob Taobao
实例 2
#!/bin/bashcat test.txt | while read line
do
echo $line
done
执行输出结果为:
Google Runoob Taobao
实例 3
for line in `cat test.txt`do
echo $line
done
执行输出结果为:
Google Runoob Taobao
for 逐行读和 while 逐行读是有区别的,如:
$ cat test.txtRunoob
Taobao
$ cat test.txt | while read line; do echo $line; done
Runoob
Taobao
$ for line in $(<test.txt); do echo $line; done
Runoob
Taobao
本文来自投稿,不代表微盟圈立场,如若转载,请注明出处:https://www.vm7.com/a/ziyuan/112171.html