From f26ecbae7d6fb38db66dad8aa6db62fc6ccf85b9 Mon Sep 17 00:00:00 2001 From: Csongor Kiss Date: Sat, 2 Jul 2022 18:51:12 +0100 Subject: [PATCH] scripts/guardian-set-init.sh: make script run on darwin The version of 'sed' shipped on macOS needs a little more handholding than gnu sed commit-id:324ce8b7 --- scripts/guardian-set-init.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scripts/guardian-set-init.sh b/scripts/guardian-set-init.sh index 0c78ebdaa..a2251235a 100755 --- a/scripts/guardian-set-init.sh +++ b/scripts/guardian-set-init.sh @@ -25,7 +25,13 @@ function upsert_env_file { # replace the value if it exists, else, append it to the file if [[ -f $file ]] && grep -q "^$key=" $file; then # file has the key, update it: - sed -i "/^$key=/s/=.*/=$new_value/" $file + if [[ "$OSTYPE" == "darwin"* ]]; then + # on macOS's sed, the -i flag needs the '' argument to not create + # backup files + sed -i '' -e "/^$key=/s/=.*/=$new_value/" $file + else + sed -i -e "/^$key=/s/=.*/=$new_value/" $file + fi else # file does not have the key, add it: echo "$key=$new_value" >> $file