1
0
mirror of https://github.com/albfan/bash-ini-parser.git synced 2025-08-06 07:02:37 +03:00

choose a more standard prefix

closes #1
This commit is contained in:
albfan
2015-05-15 18:55:44 +02:00
parent 3620e29e67
commit 3a8520b348
4 changed files with 10 additions and 8 deletions

View File

@@ -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 ]