Here is small program i wrote: manini [https://github.com/zgyarmati/manini]. It's for manipulating INI config files from shell scripts. I used to use crudini [https://github.com/pixelb/crudini], but it's Python, which is not always avalible on embedded systems (like OpenWrt, Buildroot) or i don't want to install it only for this. The other way would be to parse/edit the ini file directly from shell with awk and/or sed, but it's rather error prone, so i decided to roll a command line utility for this in C, based on the library minini [https://www.compuphase.com/minini.htm].
It's pretty easy to use, just let your ini file be:
echo "akey = avalue" > /tmp/test.ini
echo "[bsection]" >> /tmp/test.ini
echo "bkey = bvalue" >> /tmp/test.ini
and in your shell script:
AKEY=`manini --get --file /tmp/test.ini akey`
BKEY=`manini --get --file /tmp/test.ini bsection bkey`
echo "A: $AKEY" e
cho "B: $BKEY"
or, if you work on only one ini file at a time, in your scripts, to save same typing just can just export the MANINI_INIFILEPATH environment variable, and forget about the --file argument:
AKEY=`manini --get akey`
BKEY=`manini --get bsection bkey`
echo "A: $AKEY"
echo "B: $BKEY"
Binary release so for only for CentOS7 on OBS [https://build.opensuse.org/package/show/home:zgyarmati:manini/manini], others coming soon, just take the source in the meantime...Share on Twitter Share on Facebook