Fix sed regular expression to be non-greedy (#129)

* Fix sed to be non-greedy

* Fix missing double quote to prevent globbing and word splitting
This commit is contained in:
R. Fuehrer 2020-01-04 13:56:01 +01:00 committed by Kevin van Zonneveld
parent 971a83ea3a
commit 5cc417485a

View File

@ -30,7 +30,7 @@ function ini_val() {
local file="${1:-}"
local sectionkey="${2:-}"
local val="${3:-}"
local delim=" = "
local delim="="
local section=""
local key=""
local current=""
@ -39,7 +39,7 @@ function ini_val() {
if [[ ! -f "${file}" ]]; then
# touch file if not exists
touch ${file}
touch "${file}"
fi
# Split on . for section. However, section is optional
@ -50,9 +50,9 @@ function ini_val() {
section="${section_default}"
fi
current=$(sed -En "/^\[/{h;d;};G;s/^${key}(.*)${delim}(.*)\n\[${section}\]$/\2/p" "${file}"|awk '{$1=$1};1')
current=$(sed -En "/^\[/{h;d;};G;s/^${key}([[:blank:]]*)${delim}(.*)\n\[${section}\]$/\2/p" "${file}"|awk '{$1=$1};1')
if ! grep -q "\[${section}\]" ${file}; then
if ! grep -q "\[${section}\]" "${file}"; then
# create section if not exists (empty line to seperate new section)
echo >> "${file}"
echo "[${section}]" >> "${file}"