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?
Just add one of the three statements after your for loop:
ALL=${ALL%,}
ALL=${ALL::-1}
ALL=${ALL%?}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With