You've already forked bash-ini-parser
mirror of
https://github.com/albfan/bash-ini-parser.git
synced 2025-08-06 07:02:37 +03:00
@@ -22,9 +22,9 @@ Issuing:
|
||||
|
||||
$ cfg_parser file.ini
|
||||
|
||||
Will declare functions per ini section called cfg.section.<section> which declares variables named as keynames so you can access its values using
|
||||
Will declare functions per ini section called cfg_section_<section> which declares variables named as keynames so you can access its values using
|
||||
|
||||
$ cfg.section.<section>
|
||||
$ cfg_section_<section>
|
||||
$ echo $key
|
||||
value
|
||||
$ echo $key2
|
||||
|
@@ -2,6 +2,8 @@
|
||||
# based on http://theoldschooldevops.com/2008/02/09/bash-ini-parser/
|
||||
#
|
||||
|
||||
PREFIX="cfg_section_"
|
||||
|
||||
function debug {
|
||||
return #abort debug
|
||||
echo $*
|
||||
@@ -29,7 +31,7 @@ function cfg_parser {
|
||||
debug "whitespace around"
|
||||
ini=( ${ini[*]/*([[:space:]])=*([[:space:]])/=} ) # remove whitespace around =
|
||||
debug
|
||||
ini=( ${ini[*]/#\\[/\}$'\n'cfg.section.} ) # set section prefix
|
||||
ini=( ${ini[*]/#\\[/\}$'\n'"$PREFIX"} ) # set section prefix
|
||||
debug
|
||||
ini=( ${ini[*]/%\\]/ \(} ) # convert text2function (1)
|
||||
debug
|
||||
@@ -60,7 +62,7 @@ function cfg_writer {
|
||||
fun="$(declare -F)"
|
||||
fun="${fun//declare -f/}"
|
||||
for f in $fun; do
|
||||
[ "${f#cfg.section}" == "${f}" ] && continue
|
||||
[ "${f#$PREFIX}" == "${f}" ] && continue
|
||||
item="$(declare -f ${f})"
|
||||
item="${item##*\{}"
|
||||
item="${item/\}}"
|
||||
@@ -74,7 +76,7 @@ function cfg_writer {
|
||||
item="${item#*;}"
|
||||
done
|
||||
eval $f
|
||||
echo "[${f#cfg.section.}]"
|
||||
echo "[${f#$PREFIX}]"
|
||||
for var in $vars; do
|
||||
eval 'local length=${#'$var'[*]}'
|
||||
if [ $length == 1 ]
|
||||
|
@@ -20,7 +20,7 @@ echo show some results:
|
||||
|
||||
echo
|
||||
echo enable section \'sec2\'
|
||||
cfg.section.sec2
|
||||
cfg_section_sec2
|
||||
|
||||
echo "var2 value is \"$var2\""
|
||||
echo "var5[1] value is \"${var5[1]}"\"
|
||||
@@ -29,6 +29,6 @@ echo "var4 value is \"$var4"\"
|
||||
|
||||
echo
|
||||
echo enable section \'sec1\'
|
||||
cfg.section.sec1
|
||||
cfg_section_sec1
|
||||
|
||||
echo "var2 value is \"$var2\""
|
||||
|
@@ -15,7 +15,7 @@ cfg_writer
|
||||
echo
|
||||
|
||||
# enable section selected
|
||||
cfg.section.$TEST_SECTION
|
||||
cfg_section_$TEST_SECTION
|
||||
|
||||
# show value of section selected
|
||||
echo "$TEST_VALUE value is \"${!TEST_VALUE}\""
|
||||
|
Reference in New Issue
Block a user