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

后端 未结 30 1928
萌比男神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:22

    Use the set built-in to load up the $@ array:

    IN="bla@some.com;john@home.com"
    IFS=';'; set $IN; IFS=$' \t\n'
    

    Then, let the party begin:

    echo $#
    for a; do echo $a; done
    ADDR1=$1 ADDR2=$2
    

提交回复
热议问题