Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/pi-hole/pi-hole.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Warner <me@adamwarner.co.uk>2022-11-10 02:37:30 +0300
committerGitHub <noreply@github.com>2022-11-10 02:37:30 +0300
commita8b6eb9b7007e7d51d5923342bf6165874071e34 (patch)
tree2f40e0e8069ce9eed63e9da2c152854da1e57feb
parent64e61aac4af3b7b0cd89730a811e9ff89b4d155d (diff)
parent67385b7ed43a2c68bc851b3329c72c838849beea (diff)
Touch files before addKey or addOrEditKeyValPair (#4999)development
-rwxr-xr-xadvanced/Scripts/utils.sh6
1 files changed, 6 insertions, 0 deletions
diff --git a/advanced/Scripts/utils.sh b/advanced/Scripts/utils.sh
index 1174fa62..37516472 100755
--- a/advanced/Scripts/utils.sh
+++ b/advanced/Scripts/utils.sh
@@ -31,6 +31,9 @@ addOrEditKeyValPair() {
local key="${2}"
local value="${3}"
+ # touch file to prevent grep error if file does not exist yet
+ touch "${file}"
+
if grep -q "^${key}=" "${file}"; then
# Key already exists in file, modify the value
sed -i "/^${key}=/c\\${key}=${value}" "${file}"
@@ -51,6 +54,9 @@ addKey(){
local file="${1}"
local key="${2}"
+ # touch file to prevent grep error if file does not exist yet
+ touch "${file}"
+
if ! grep -q "^${key}" "${file}"; then
# Key does not exist, add it.
echo "${key}" >> "${file}"