I want split the string with delimiter comma and write it to a file. I have the below script but when I see the output(temp.txt) I see the complete for loop code written to file.. Can anyone help me to fix this issue
#!/bin/bash -e
string1=a/b,b/c,c/d
IFS=', ' read -a array <<< "$string1"
cat << 'EOF' > temp.txt
for element in "${array[@]}"
do
echo "$element"
done
EOF
Expected file temp.txt output
a/b
b/c
c/d