I am struggling earlier with a string splitting in bash. After some search i have found two method of doing this that split a string and make an array of that splitted parts.
But when i am printing them i am getting different result.
a="hello,hi,hola"
Method 1:
IFS=',' read -ra arr <<< "$a"
echo "${arr[@]}"
Output:
hello hi hola
Method 2:
arr=$(echo $a | tr "," "\n")
echo "${arr[@]}"
Output:
hello
hi
hola
What is the reason behind this?