How do I "read" a variable on a while loop How do I "read" a variable on a while loop bash bash

How do I "read" a variable on a while loop


You can write:

while IFS= read -r linedo    echo "$line"done <<< "$the_list"

See ยง3.6.7 "Here Strings" in the Bash Reference Manual.

(I've also taken the liberty of adding some double-quotes, and adding -r and IFS= to read, to avoid too much mucking around with the contents of your variables.)


If you do not use the variable for anything else, you can even do without it:

while read line ; do    echo $linedone < <( ... code ... )


You can just use

your_code | while read line;do    echo $linedone

if you don't mind the while loop executing in a subshell (any variables you modify won't be visible in the parent after the done).