Redirect output to a bash array

前端 未结 5 1229
感动是毒
感动是毒 2020-12-14 02:39

I have a file containing the string

ipAddress=10.78.90.137;10.78.90.149

I\'d like to place these two IP addresses in a bash array. To achie

5条回答
  •  臣服心动
    2020-12-14 03:32

    This one works:

    n=(`grep -i ipaddress filename | cut -d"=" -f2 | tr ';' ' '`)
    

    EDIT: (improved, nestable version as per Dennis)

    n=($(grep -i ipaddress filename | cut -d"=" -f2 | tr ';' ' '))
    

提交回复
热议问题