一、使用for方法读取文件内容
#!/bin/bash
for line in `cat 文件名`
do
....
done
二、使用while循环结合read命令逐行读取文件内容
1、方法1
cat "文件名" | while read line
do
done
2、方法2
exec < demo.txt //读取文件
while read line
do
........
done
3、方法3
while read line
do
........
done <demo.txt //将整个while循环的标准输入指向文件
参考:linux shell脚本中读取文件内容的方法(含效率测试)_storyteller的博客-CSDN博客_linux shell 读取文本