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 {
|
function debug {
|
||||||
if ! [ "x$BASH_INI_PARSER_DEBUG" == "x" ]
|
if ! [ "x$BASH_INI_PARSER_DEBUG" == "x" ]
|
||||||
then
|
then
|
||||||
echo $*
|
echo
|
||||||
echo --start--
|
echo --start-- $*
|
||||||
echo "${ini[*]}"
|
echo "${ini[*]}"
|
||||||
echo --end--
|
echo --end--
|
||||||
echo
|
echo
|
||||||
@@ -39,10 +39,21 @@ function cfg_parser {
|
|||||||
debug
|
debug
|
||||||
ini=( ${ini[*]/%+([[:space:]])/} ) # remove ending whitespace
|
ini=( ${ini[*]/%+([[:space:]])/} ) # remove ending whitespace
|
||||||
debug "whitespace around ="
|
debug "whitespace around ="
|
||||||
|
ini=( ${ini[*]/%+([[:space:]])\\]/\\]} ) # remove non meaningful whitespace after sections
|
||||||
|
debug "whitespace around ="
|
||||||
ini=( ${ini[*]/*([[:space:]])=*([[:space:]])/=} ) # remove whitespace around =
|
ini=( ${ini[*]/*([[:space:]])=*([[:space:]])/=} ) # remove whitespace around =
|
||||||
debug
|
debug
|
||||||
ini=( ${ini[*]/#\\[/\}$'\n'"$PREFIX"} ) # set section prefix
|
ini=( ${ini[*]/#\\[/\}$'\n'"$PREFIX"} ) # set section prefix
|
||||||
debug
|
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)
|
ini=( ${ini[*]/%\\]/ \(} ) # convert text2function (1)
|
||||||
debug
|
debug
|
||||||
ini=( ${ini[*]/=/=\( } ) # convert item to array
|
ini=( ${ini[*]/=/=\( } ) # convert item to array
|
||||||
|
@@ -17,4 +17,7 @@ var5=section 2 VAR 5
|
|||||||
var1="section 3 VAR 1"
|
var1="section 3 VAR 1"
|
||||||
var2= "section 3 VAR 2"
|
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]
|
[section3]
|
||||||
var1="section 3 VAR 1"
|
var1="section 3 VAR 1"
|
||||||
var2="section 3 VAR 2"
|
var2="section 3 VAR 2"
|
||||||
|
[section4_subsec]
|
||||||
|
var1="section 3 VAR 1"
|
||||||
|
var2="section 3 VAR 2"
|
||||||
|
Reference in New Issue
Block a user