Bash Looping through a string line by line


Example

var='line 1
line 2
line3'
while IFS= read -r line; do
   echo "-$line-"
done <<< "$var"

or

readarray -t arr <<< "$var"
for i in "${arr[@]}";do
    echo "-$i-"
done