如何在Shell脚本中逐行读取文件

1、创建一个名为“ example1.sh”的脚本,该脚本使用输入重定向和循环:

[root@localhost ~]# cat example1.sh 
#!/bin/bash
while read rows
do
  echo "Line contents are : $rows "
done < mycontent.txt



2、[root@localhost ~]# cat example2.sh 
#!/bin/bash
cat mycontent.txt | while read rows
do
  echo "Line contents are : $rows "
done
原文地址:https://www.cnblogs.com/cheyunhua/p/14701967.html