mirror of
https://github.com/kvz/bash3boilerplate.git
synced 2025-04-25 05:19:40 +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
@ -39,7 +39,7 @@ function ini_val() {
|
|||||||
|
|
||||||
if [[ ! -f "${file}" ]]; then
|
if [[ ! -f "${file}" ]]; then
|
||||||
# touch file if not exists
|
# touch file if not exists
|
||||||
touch ${file}
|
touch "${file}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Split on . for section. However, section is optional
|
# Split on . for section. However, section is optional
|
||||||
@ -50,9 +50,9 @@ function ini_val() {
|
|||||||
section="${section_default}"
|
section="${section_default}"
|
||||||
fi
|
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)
|
# create section if not exists (empty line to seperate new section)
|
||||||
echo >> "${file}"
|
echo >> "${file}"
|
||||||
echo "[${section}]" >> "${file}"
|
echo "[${section}]" >> "${file}"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user