how to split string in bash shell code example
Example 1: split string and create array bash
IFS=', ' read -r -a array <<< "$string"
Example 2: bash split string into variables
VAR="inforge srl bergamo"
read -r ONE TWO THREE <<< "${VAR}"
echo ${ONE}
echo ${TWO}
echo ${THREE}
VAR="inforge,srl,bergamo"
IFS="," read -r ONE TWO THREE <<< "${VAR}"
echo "${ONE} ${TWO} ${THREE}"
Example 3: split bash string
IN="[email protected];[email protected]"
arrIN=(${IN//;/ })
Example 4: bash split variable by delimiter
IFS='|' read -r -a arrayName <<< "$variable"