while read test; do echo $test done <<< "$(seq 5)"
Run seq 5 , collecting the result in a temporary variable. Then run a while loop, yielding the result of the collection.
while read test; do echo $test done < <(seq 5)
Set up a subshell to run seq 5 and connect its stdout to stdin . Then run the while loop. When it ends, restore stdin .
What's the difference? For seq 5 almost nothing; however, it can be made visible by changing seq 5 to seq 5; echo done generating sequence >&2 seq 5; echo done generating sequence >&2 . Then you can see that in the first case, the execution of all seq ends before the start of the while , and in the second case, they are executed in parallel.
$ while read n; do echo $n > /dev/stderr; done \ > <<<"$(seq 5; echo done generating sequence >&2)" done generating sequence 1 2 3 4 5 $ while read n; do echo $n > /dev/stderr; done \ > < <(seq 5; echo done generating sequence >&2) 1 2 done generating sequence 3 4 5
If it were a seq 10000000 , the difference would be much clearer. The form <<<"$(...) would use a lot more memory to store the time line.
source share