diff --git a/bash-ini-parser b/bash-ini-parser index 3fdf885..e7f6b70 100755 --- a/bash-ini-parser +++ b/bash-ini-parser @@ -7,8 +7,8 @@ PREFIX="cfg_section_" function debug { if ! [ "x$BASH_INI_PARSER_DEBUG" == "x" ] then - echo $* - echo --start-- + echo + echo --start-- $* echo "${ini[*]}" echo --end-- echo @@ -39,10 +39,21 @@ function cfg_parser { debug ini=( ${ini[*]/%+([[:space:]])/} ) # remove ending whitespace debug "whitespace around =" + ini=( ${ini[*]/%+([[:space:]])\\]/\\]} ) # remove non meaningful whitespace after sections + debug "whitespace around =" ini=( ${ini[*]/*([[:space:]])=*([[:space:]])/=} ) # remove whitespace around = debug ini=( ${ini[*]/#\\[/\}$'\n'"$PREFIX"} ) # set section prefix debug + for ((i=0; i < "${#ini[@]}"; i++)) + do + line="${ini[i]}" + if [[ "$line" =~ $PREFIX.+ ]] + then + ini[$i]=${line// /_} + fi + done + debug "subsections" ini=( ${ini[*]/%\\]/ \(} ) # convert text2function (1) debug ini=( ${ini[*]/=/=\( } ) # convert item to array diff --git a/t/t0003/sections.ini b/t/t0003/sections.ini index 365a367..f055795 100644 --- a/t/t0003/sections.ini +++ b/t/t0003/sections.ini @@ -17,4 +17,7 @@ var5=section 2 VAR 5 var1="section 3 VAR 1" var2= "section 3 VAR 2" +[section4 subsec] +var1="section 3 VAR 1" +var2= "section 3 VAR 2" diff --git a/t/t0003/sections.out.correct b/t/t0003/sections.out.correct index 13c9c8c..f8def2b 100644 --- a/t/t0003/sections.out.correct +++ b/t/t0003/sections.out.correct @@ -15,3 +15,6 @@ var5="section 2 VAR 5" [section3] var1="section 3 VAR 1" var2="section 3 VAR 2" +[section4_subsec] +var1="section 3 VAR 1" +var2="section 3 VAR 2"