相关疑难解决方法(0)

Bash:如何从命令的输出中一次读取一行?

我正在尝试使用 .bash 文件读取 bash 中命令的输出while loop

while read -r line
do
    echo "$line"
done <<< $(find . -type f)
Run Code Online (Sandbox Code Playgroud)

我得到的输出

ranveer@ranveer:~/tmp$ bash test.sh
./test.py ./test1.py ./out1 ./test.sh ./out ./out2 ./hello
ranveer@ranveer:~/tmp$ 
Run Code Online (Sandbox Code Playgroud)

在这之后我试过了

$(find . -type f) | 
while read -r line
do
    echo "$line"
done 
Run Code Online (Sandbox Code Playgroud)

但它产生了一个错误test.sh: line 5: ./test.py: Permission denied

那么,我如何逐行阅读它,因为我认为目前它正在一次吞食整行。

所需输出:

./test.py
./test1.py
./out1
./test.sh
./out
./out2
./hello
Run Code Online (Sandbox Code Playgroud)

shell bash pipe find

63
推荐指数
3
解决办法
15万
查看次数

标签 统计

bash ×1

find ×1

pipe ×1

shell ×1