linux shell 脚本读取 ini 配置文件

来源:互联网 发布:欧陆风云4mac汉化补丁 编辑:程序博客网 时间:2024/05/20 13:19

linux shell 脚本读取 ini 配置档打码如下:

#!/bin/bashconfigFile="./config.ini"function ReadINIfile()  {   Key=$1Section=$2  Configfile=$3ReadINI=`awk -F '=' '/\['$Section'\]/{a=1}a==1&&$1~/'$Key'/{print $2;exit}' $Configfile`   echo "$ReadINI"  } itemCount=`ReadINIfile "ItemCount" "General" "$configFile"`echo $itemCountfor((i=0; i<itemCount; i++))doSection="Item""$i"echo $SectionnumTest=`ReadINIfile "NumTest" "$Section" "$configFile"`stringTest=`ReadINIfile "StringTest" "$Section" "$configFile"`echo $numTestecho $stringTestdone


测试的ini配置档如下:

[General]ItemCount=2 [Item0]NumTest=100StringTest=for string test 0 [Item1]NumTest=111StringTest=for string test 1

测试结果如下:

2Item0100for string test 0Item1111for string test 1


 

0 0