Bash Read lines of a string into an array


Example

var='line 1
line 2
line3'
readarray -t arr <<< "$var"

or with a loop:

arr=()
while IFS= read -r line; do
   arr+=("$line")
done <<< "$var"