Quantcast
Channel: Bash: How to read one line at a time from output of a command? - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 7

Bash: How to read one line at a time from output of a command?

$
0
0

I am trying to read the output of a command in bash using a while loop.

while read -r linedo    echo "$line"done <<< $(find . -type f)

The output I got

ranveer@ranveer:~/tmp$ bash test.sh./test.py ./test1.py ./out1 ./test.sh ./out ./out2 ./helloranveer@ranveer:~/tmp$ 

After this I tried

$(find . -type f) | while read -r linedo    echo "$line"done 

but it generated an error test.sh: line 5: ./test.py: Permission denied.

So, how do I read it line by line because I think currently it is slurping the entire line at once.

Required output:

./test.py./test1.py./out1./test.sh./out./out2./hello

Viewing all articles
Browse latest Browse all 7

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>