1
while read line do echo $line done < filename
2
cat filename | while read line do echo $line done
3
for line in $(cat filename) do echo $line done
注:while逐行读取和for逐行读取有区别——while每次读取一行,for每次读取由空白分割的一部分;
$ cat file 1111 2222 3333 4444 555 $ cat file | while read line; do echo $line; done 1111 2222 3333 4444 555 $ for line in $(cat file); do echo $line; done 1111 2222 3333 4444 555原文链接:https://www.f2er.com/bash/392992.html