You've already forked bash-ini-parser
mirror of
https://github.com/albfan/bash-ini-parser.git
synced 2025-08-09 05:22:44 +03:00
Allow subsections
This commit is contained in:
@@ -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
|
||||
|
@@ -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"
|
||||
|
||||
|
@@ -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"
|
||||
|
Reference in New Issue
Block a user