I have an array whose elements may contain spaces:
set ASD "a" "b c" "d"
How can I convert this array to a single string of comma-separated values?
# what I want:
"a,b c,d"
So far the closest I could get was converting the array to a string and then replacing all the spaces. The problem is that this only works if the array elements don't contain spaces themselves
(echo $ARR | tr ' ' ',')
cut
/sed
approaches only work if the elements of the array don't contain newline characters.tail -c +2
would be more appropriate. – Stéphane Chazelas Feb 05 '18 at 15:29