How can I join elements of an array in Bash?

前端 未结 30 2633
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 12:05

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.

30条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-22 12:35

    My attempt.

    $ array=(one two "three four" five)
    $ echo "${array[0]}$(printf " SEP %s" "${array[@]:1}")"
    one SEP two SEP three four SEP five
    

提交回复
热议问题