xxxxxxxxxx
my_array=($(echo $string | tr "," "\n"))
xxxxxxxxxx
string="you got a friend in me"
IFS=' ' read -ra split <<< "$string"
echo "${split[*]}"
# Output: you got a friend in me
echo "${split[3]}"
# Output: friend
xxxxxxxxxx
#!/bin/bash
# Define the string to be splitted
string="Hello,World,How,Are,You"
# Split the string using a delimiter (comma in this case)
IFS=',' read -ra parts <<< "$string"
# Print each part of the splitted string
for part in "${parts[@]}"; do
echo "$part"
done
xxxxxxxxxx
text="Hello,World,Devs"
# Set comma as delimiter
IFS=','
#Read the split words into an array based on comma delimiter
read -a strarr <<< "$text"
#Print the split words
echo "index 0 : ${strarr[0]}" # Hello
echo "index 1 : ${strarr[1]}" # World
echo "index 2: ${strarr[2]}" # Devs