我正在尝试使用 .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)