Shell读取ini文件

参考stackoverflow的例子,改了一个出来:

while IFS='= ' read var val
do
    if [[ $var == \[*] ]]
    then
        section=$(echo $var | sed 's/^\[\(.*\)\]$//')
    elif [[ $val ]]
    then
        if [ -z $section ];then
            declare "${var}=$val"
        else
            declare "${section}.${var}=$val"
        fi  
    fi  
done < config.ini

使用的时候:

就可以读到变量啦。

Leave a Reply

Your email address will not be published.