If I have an array like this in Bash:
FOO=( a b c )
How do I join the elements with commas? For example, producing a,b,c.
a,b,c
This approach takes care of spaces within the values, but requires a loop:
#!/bin/bash FOO=( a b c ) BAR="" for index in ${!FOO[*]} do BAR="$BAR,${FOO[$index]}" done echo ${BAR:1}