Iterating over multiple-line string stored in variable
In modern shells like bash and zsh, you have a very useful `<<<' redirector that accepts a string as an input. So you would do
while IFS= read -r line ; do echo $line; done <<< "$variable"
Otherwise, you can always do
echo "$variable" | while IFS= read -r line ; do echo $line; done