2021年4月12日

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

运行截图:


“以书为舟,遨游尘世”,
最好的免费 kindle 电子书分享站:

You may also like...

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注


*