I have this string stored in a variable:
IN=\"bla@some.com;john@home.com\"
Now I would like to split the strings by ;
delimite
Taken from Bash shell script split array:
IN="bla@some.com;john@home.com"
arrIN=(${IN//;/ })
Explanation:
This construction replaces all occurrences of ';'
(the initial //
means global replace) in the string IN
with ' '
(a single space), then interprets the space-delimited string as an array (that's what the surrounding parentheses do).
The syntax used inside of the curly braces to replace each ';'
character with a ' '
character is called Parameter Expansion.
There are some common gotchas:
IFS=':'; arrIN=($IN); unset IFS;
IFS=$'\n'; arrIN=($IN); unset IFS;