How can I join elements of an array in Bash?

前端 未结 30 2612
爱一瞬间的悲伤
爱一瞬间的悲伤 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:16

    Right now I'm using:

    TO_IGNORE=(
        E201 # Whitespace after '('
        E301 # Expected N blank lines, found M
        E303 # Too many blank lines (pep8 gets confused by comments)
    )
    ARGS="--ignore `echo ${TO_IGNORE[@]} | tr ' ' ','`"
    

    Which works, but (in the general case) will break horribly if array elements have a space in them.

    (For those interested, this is a wrapper script around pep8.py)

提交回复
热议问题