From 2cb0eabd10a37d3905c3410b47ea170fed762513 Mon Sep 17 00:00:00 2001 From: Pedro G Date: Mon, 27 Mar 2017 19:42:38 +0200 Subject: [PATCH 1/2] fixing bash for archlinux --- read_ini.sh | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/read_ini.sh b/read_ini.sh index 2ae2a85..e8b1960 100755 --- a/read_ini.sh +++ b/read_ini.sh @@ -12,7 +12,7 @@ # # - +set -x function read_ini() @@ -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 @@ -274,7 +274,7 @@ function read_ini() eval "$VARNAME=$VAL" done <"${INI_FILE}" - + # return also the number of parsed sections eval "$INI_NUMSECTIONS_VARNAME=$SECTIONS_NUM" From c366f3083f5d5af6f733ff2f43fb5f2c31677295 Mon Sep 17 00:00:00 2001 From: Pedro G Date: Mon, 27 Mar 2017 19:48:55 +0200 Subject: [PATCH 2/2] fixing identation --- read_ini.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/read_ini.sh b/read_ini.sh index e8b1960..e9dee68 100755 --- a/read_ini.sh +++ b/read_ini.sh @@ -12,7 +12,7 @@ # # -set -x + function read_ini() @@ -274,7 +274,7 @@ echo line = "$line" eval "$VARNAME=$VAL" done <"${INI_FILE}" - + # return also the number of parsed sections eval "$INI_NUMSECTIONS_VARNAME=$SECTIONS_NUM"