There are many methods, here are three methods:
Writing method one:
#!/bin/bash while read line do echo $line done < filename(待读取的文件)
Writing method two:
#!/bin/bash cat filename(待读取的文件) | while read line do echo $line done
Writing method three:
for line in `cat filename(待读取的文件)` do echo $line done
Explanation:# There is a difference between ##for line-by-line reading and while line-by-line reading, such as:
$ cat file 1111 2222 3333 4444 555 $ cat file | while read line; do echo $line; done 1111 2222 3333 4444 555 $ for line in $(<file); do echo $line; done 1111 2222 3333 4444 555
For more 3 methods of shell reading files line by line, please pay attention to the PHP Chinese website for related articles !