From 5cc417485a7a5cae8d1eec79fd7a1f4dc15f34b7 Mon Sep 17 00:00:00 2001 From: "R. Fuehrer" Date: Sat, 4 Jan 2020 13:56:01 +0100 Subject: [PATCH] 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 --- src/ini_val.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ini_val.sh b/src/ini_val.sh index 1fbf24b..62d59f7 100755 --- a/src/ini_val.sh +++ b/src/ini_val.sh @@ -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}"