bash 按行读取内容

两种写法:

#!/bin/bash

# 写法1
cat test.txt | while read line
do
    echo "1:${line}"
done

# 写法2
while read line
do
    echo "2:${line}"
done < test.txt

运行截图: