mirror of
https://github.com/pi-hole/pi-hole
synced 2024-12-22 14:58:08 +00:00
Touch files before addKey or addOrEditKeyValPair (#4999)
This commit is contained in:
commit
a8b6eb9b70
@ -31,6 +31,9 @@ addOrEditKeyValPair() {
|
|||||||
local key="${2}"
|
local key="${2}"
|
||||||
local value="${3}"
|
local value="${3}"
|
||||||
|
|
||||||
|
# touch file to prevent grep error if file does not exist yet
|
||||||
|
touch "${file}"
|
||||||
|
|
||||||
if grep -q "^${key}=" "${file}"; then
|
if grep -q "^${key}=" "${file}"; then
|
||||||
# Key already exists in file, modify the value
|
# Key already exists in file, modify the value
|
||||||
sed -i "/^${key}=/c\\${key}=${value}" "${file}"
|
sed -i "/^${key}=/c\\${key}=${value}" "${file}"
|
||||||
@ -51,6 +54,9 @@ addKey(){
|
|||||||
local file="${1}"
|
local file="${1}"
|
||||||
local key="${2}"
|
local key="${2}"
|
||||||
|
|
||||||
|
# touch file to prevent grep error if file does not exist yet
|
||||||
|
touch "${file}"
|
||||||
|
|
||||||
if ! grep -q "^${key}" "${file}"; then
|
if ! grep -q "^${key}" "${file}"; then
|
||||||
# Key does not exist, add it.
|
# Key does not exist, add it.
|
||||||
echo "${key}" >> "${file}"
|
echo "${key}" >> "${file}"
|
||||||
|
Loading…
Reference in New Issue
Block a user