Split string into an array in Bash

后端 未结 22 2784
故里飘歌
故里飘歌 2020-11-22 04:24

In a Bash script I would like to split a line into pieces and store them in an array.

The line:

Paris, France, Europe

I would like

22条回答
  •  感动是毒
    2020-11-22 04:43

    For multilined elements, why not something like

    $ array=($(echo -e $'a a\nb b' | tr ' ' '§')) && array=("${array[@]//§/ }") && echo "${array[@]/%/ INTERELEMENT}"
    
    a a INTERELEMENT b b INTERELEMENT
    

提交回复
热议问题