tags:

views:

117

answers:

1

I want to create a var from the section names of an ini file like:

[foo]
; ...

[bar]
; ...

[baz:bar]
;...

now I need a var like

SECTIONS="foo bar baz"

thanks in advance

A: 

i'M now using this construct, don't need to know if a section exists. just read it, it it's empty it does not exist :D

INI_FILE=test.ini

function ini_get
{

    eval `sed -e 's/[[:space:]]*\=[[:space:]]*/=/g' \
        -e 's/;.*$//' \
        -e 's/[[:space:]]*$//' \
        -e 's/^[[:space:]]*//' \
        -e "s/^\(.*\)=\([^\"']*\)$/\1=\"\2\"/" \
    < $INI_FILE \
    | sed -n -e "/^\[$1\]/,/^\s*\[/{/^[^;].*\=.*/p;}"

    echo ${!2}
}


IP=$(ini_get 50001 ip)
PORT=$(ini_get 50001 port)
echo $IP:$PORT
zolex