In a Bash script I would like to split a line into pieces and store them in an array.
The line:
Paris, France, Europe
I would like
The accepted answer works for values in one line.
If the variable has several lines:
string='first line
second line
third line'
We need a very different command to get all lines:
while read -r line; do lines+=("$line"); done <<<"$string"
Or the much simpler bash readarray:
readarray -t lines <<<"$string"
Printing all lines is very easy taking advantage of a printf feature:
printf ">[%s]\n" "${lines[@]}"
>[first line]
>[ second line]
>[ third line]