mirror of
https://github.com/kvz/bash3boilerplate.git
synced 2025-04-23 23:03:34 +00:00
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:
parent
971a83ea3a
commit
5cc417485a
@ -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}"
|
||||
|
Loading…
x
Reference in New Issue
Block a user