- cat filename.txt |while read LINE
- do
- echo $LINE
- done
- # LINE 在这里面只是随便一个变量, 并不是内置
或者
- #!/bin/bash
- while read aa
- do
- echo $aa
- done< filename.txt
- # 这种格式看起来更好
- #!/bin/bash
- myfile=filename.txt
- count=0
- cat $myfile |while read LINE
- do
- echo $LINE
- let count=count+1
- echo $count line
- done
- [root@localhost prog]# cat filename.txt This is line number 1 This is line number 2 This is line number 3 This is line number 4 This is line number 5 This is line number 6 This is line number 7 This is line number 8 This is line number 9 This is line number 10
来源: http://www.bubuko.com/infodetail-2850211.html