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

Answer by Franois-Frdric Ozog Shokubai for Bash: How to read one line at a time from output of a command?

$
0
0

A key element to consider how to choose the right form is variable visibility.

result=""find . -type f | while read linedo    result="$result $line"doneecho "result pipe=$result"while read linedo    result="$result $line"done < <(find . -type f)echo "result redirect input=$result"

gives the result in a directory that contains a, b, and c files

result pipe=result redirect input= ./c ./b ./a

"result pipe" will always be empty in the first form because the while loop executes in a secondary process."result redirect input" will give the list of files because the while loop executes in the current process.


Viewing all articles
Browse latest Browse all 7

Trending Articles



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