I am trying to read the output of a command in bash using a while loop
.
while read -r line
do
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 ./hello
ranveer@ranveer:~/tmp$
After this I tried
$(find . -type f) |
while read -r line
do
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
while read
part, see Understanding IFS and the questions linked there. – Gilles 'SO- stop being evil' Oct 16 '12 at 22:38find
, see How can I use two bash commands in -exec of find command? or Executing user defined function in a find -exec call (which this question is mostly a duplicate of). – Gilles 'SO- stop being evil' Oct 16 '12 at 22:40