测试文件: 测试的相关代码: #!/bin/bash while read line do echo $line done < test.txt #!/bin/bash cat test.txt | while read line do echo $line done 在文件夹中加入test.txt和homework.sh 切换到此文件夹 执行方式1: chmod +x ./homework.sh ./homework.sh 执行方式2: bash homework.sh 测试结果