How do I split a string on a delimiter in Bash?

后端 未结 30 1922
萌比男神i
萌比男神i 2020-11-21 04:58

I have this string stored in a variable:

IN=\"bla@some.com;john@home.com\"

Now I would like to split the strings by ; delimite

30条回答
  •  灰色年华
    2020-11-21 05:37

    If you don't mind processing them immediately, I like to do this:

    for i in $(echo $IN | tr ";" "\n")
    do
      # process
    done
    

    You could use this kind of loop to initialize an array, but there's probably an easier way to do it. Hope this helps, though.

提交回复
热议问题