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

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

    There is a simple and smart way like this:

    echo "add:sfff" | xargs -d: -i  echo {}
    

    But you must use gnu xargs, BSD xargs cant support -d delim. If you use apple mac like me. You can install gnu xargs :

    brew install findutils
    

    then

    echo "add:sfff" | gxargs -d: -i  echo {}
    

提交回复
热议问题