How is it possible to split a string to an array?
#!/bin/sh
eg.
str="field 1,field 2,field 3,field 4"
The length of the arrays is various
Have found alot of solutions but they only works in bash
update
This only works if the length of the array has 4 values, but what if it has 10 values?
The for loop doesn't seem to work
arr=$(echo "field 1,field 2,field 3,field 4" | awk '{split($0,a,","); print a[1],a[2],a[3],a[4]}');
for value in ${arr[@]}
do
echo "$value\n"
done
,or ` `bash,zsh, probably others) that does.