BASH - Files - Read a file - Input source selection

Usually read has a filename as its input.

To instead use the contents of a variable/parameter as the file to read:

while IFS= read -r line; do
  printf '%s\n' "$line"
done <<< "$var"

The same can be done in any Bourne-type shell by using a “here document” (although read -r is POSIX, not Bourne):

while IFS= read -r line; do
  printf '%s\n' "$line"
done <<EOF
$var
EOF