I want to add the values to a variable, separated by comma, using for loop. First values should remain first and so on.
for ((i=0; i<${#MYARRAY[@]}; i++));
do
ALL=$ALL$MYARRAY$i,
done
echo $ALL
I expect the output val1,val2,val3 but the actuel output is val1,val2,val3,
How to avoid the comma after the last value?
+=. Here is all that combined:all+=${myarray[$i]},and you should always quote your variables:echo "$all"