Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions read_ini.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function read_ini()
return 1
fi
}

function check_ini_file()
{
if [ ! -r "$INI_FILE" ] ;then
Expand All @@ -34,7 +34,7 @@ function read_ini()
return 1
fi
}

# enable some optional shell behavior (shopt)
function pollute_bash()
{
Expand All @@ -46,15 +46,15 @@ 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()
{
shopt -q -u ${SWITCH_SHOPT}
unset -f check_prefix check_ini_file pollute_bash cleanup_bash
}

local INI_FILE=""
local INI_SECTION=""

Expand Down Expand Up @@ -140,7 +140,7 @@ function read_ini()
cleanup_bash
return 0
fi

if ! check_ini_file ;then
cleanup_bash
return 1
Expand All @@ -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}" = "#" ]
Expand All @@ -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
Expand Down Expand Up @@ -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:]])}"
Expand Down Expand Up @@ -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
Expand Down