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
Another way to do it without modifying IFS:
read -r -a myarray <<< "${string//, /$IFS}"
Rather than changing IFS to match our desired delimiter, we can replace all occurrences of our desired delimiter ", "
with contents of $IFS
via "${string//, /$IFS}"
.
Maybe this will be slow for very large strings though?
This is based on Dennis Williamson's answer.