From f2c5703806e66521c1f030a88bc221f811d18499 Mon Sep 17 00:00:00 2001 From: albfan Date: Sat, 16 May 2015 20:37:43 +0200 Subject: [PATCH] operate by section --- bash-ini-parser | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/bash-ini-parser b/bash-ini-parser index 5fb7027..4798d62 100644 --- a/bash-ini-parser +++ b/bash-ini-parser @@ -61,9 +61,20 @@ function cfg_parser { } function cfg_writer { + SECTION=$1 OLDIFS="$IFS" IFS=' '$'\n' - fun="$(declare -F)" + if [ -z "$SECTION" ] + then + fun="$(declare -F)" + else + fun="$(declare -F $PREFIX$SECTION)" + if [ -z "$fun" ] + then + echo "section $SECTION not found" >2 + exit 1 + fi + fi fun="${fun//declare -f/}" for f in $fun; do [ "${f#$PREFIX}" == "${f}" ] && continue @@ -135,9 +146,20 @@ function cfg_unset { } function cfg_clear { + SECTION=$1 OLDIFS="$IFS" IFS=' '$'\n' - fun="$(declare -F)" + if [ -z "$SECTION" ] + then + fun="$(declare -F)" + else + fun="$(declare -F $PREFIX$SECTION)" + if [ -z "$fun" ] + then + echo "section $SECTION not found" >2 + exit 1 + fi + fi fun="${fun//declare -f/}" for f in $fun; do [ "${f#$PREFIX}" == "${f}" ] && continue @@ -152,7 +174,7 @@ function cfg_update { OLDIFS="$IFS" IFS=' '$'\n' fun="$(declare -F $PREFIX$SECTION)" - if [ -z $fun ] + if [ -z "$fun" ] then echo "section $SECTION not found" >2 exit 1