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

运行截图:


“谈笑有鸿儒,往来无白丁”,
社长桩白墨邀你加入星链社区,
开启365天的浪漫生活。

You may also like...

发表回复

您的电子邮箱地址不会被公开。


*