编写shell脚本读取ini配置文件

怎么读取ini配置文件中的ip地址? 

1. 我的ini配置文件

[all]

www.badiu1.com ip=10.232.10.27

www.badiu2.com ip=10.232.10.28

www.badiu3.com ip=10.232.10.29

 

我想要获得 ip地址的数组。

2. 我自己写的 awk 命令

         iniValue=`awk -F '=' "/\[${section}\]/{a=1}a==1" ${iniFile}|sed -e '1d' -e '/^$/d' -e '/^\[.*\]/,$d' -e "/^${option}.*=.*/!d" -e "s/^${option}.*= *//"`

 只能在 ip 在最左端生效,能帮忙看看吗? 


# 将awk命令的输出存储到ip_addresses数组中
ip_addresses=($(awk -F '=' '/ip=/ {print $2}' ${iniFile}))

# 获取ip_addresses数组的长度
length=${#ip_addresses[@]}
echo "IP Addresses Count: $length"

# 使用for循环遍历ip_addresses数组的所有元素
echo "IP Addresses:"
for ((i = 0; i < length; i++)); do
  echo "${ip_addresses[i]}"
done