diff --git a/read_ini.sh b/read_ini.sh index 2ae2a85..e9dee68 100755 --- a/read_ini.sh +++ b/read_ini.sh @@ -25,7 +25,7 @@ function read_ini() return 1 fi } - + function check_ini_file() { if [ ! -r "$INI_FILE" ] ;then @@ -34,7 +34,7 @@ function read_ini() return 1 fi } - + # enable some optional shell behavior (shopt) function pollute_bash() { @@ -46,7 +46,7 @@ function read_ini() fi shopt -q -s ${SWITCH_SHOPT} } - + # unset all local functions and restore shopt settings before returning # from read_ini() function cleanup_bash() @@ -54,7 +54,7 @@ function read_ini() shopt -q -u ${SWITCH_SHOPT} unset -f check_prefix check_ini_file pollute_bash cleanup_bash } - + local INI_FILE="" local INI_SECTION="" @@ -140,7 +140,7 @@ function read_ini() cleanup_bash return 0 fi - + if ! check_ini_file ;then cleanup_bash return 1 @@ -160,21 +160,21 @@ function read_ini() local LINE_NUM=0 local SECTIONS_NUM=0 local SECTION="" - + # IFS is used in "read" and we want to switch it within the loop local IFS=$' \t\n' local IFS_OLD="${IFS}" - + # we need some optional shell behavior (shopt) but want to restore # current settings before returning local SWITCH_SHOPT="" pollute_bash - + while read -r line || [ -n "$line" ] do -#echo line = "$line" +echo line = "$line" - ((LINE_NUM++)) + LINE_NUM=$(($LINE_NUM + 1)) # Skip blank lines and comments if [ -z "$line" -o "${line:0:1}" = ";" -o "${line:0:1}" = "#" ] @@ -190,7 +190,7 @@ function read_ini() SECTION="${line#[}" SECTION="${SECTION%]}" eval "${INI_ALL_SECTION}=\"\${${INI_ALL_SECTION}# } $SECTION\"" - ((SECTIONS_NUM++)) + SECTIONS_NUM=$(($SECTIONS_NUM + 1)) continue fi @@ -218,7 +218,7 @@ function read_ini() IFS="=" read -r VAR VAL <<< "${line}" IFS="${IFS_OLD}" - + # delete spaces around the equal sign (using extglob) VAR="${VAR%%+([[:space:]])}" VAL="${VAL##+([[:space:]])}" @@ -265,7 +265,7 @@ function read_ini() ;; esac fi - + # enclose the value in single quotes and escape any # single quotes and backslashes that may be in the value