From 7f5862a955ab31e7642d1c7f6136ee06650febff Mon Sep 17 00:00:00 2001 From: deicidus Date: Fri, 16 Jun 2023 03:49:44 -0700 Subject: [PATCH] improved newline handline --- spells/menu/bitcoin/configure-bitcoin | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spells/menu/bitcoin/configure-bitcoin b/spells/menu/bitcoin/configure-bitcoin index dec6939..89495a0 100755 --- a/spells/menu/bitcoin/configure-bitcoin +++ b/spells/menu/bitcoin/configure-bitcoin @@ -44,7 +44,9 @@ fi modify_bitcoin_conf() { local key=$1 local value=$2 - awk -v key="$key" -v value="$value" 'BEGIN {found=0} !/^#/ && $1==key {found=1; print key"="value; next} {print} END {if (!found) print key"="value; print ""}' "$bitcoin_conf" > "$bitcoin_conf.tmp" && mv "$bitcoin_conf.tmp" "$bitcoin_conf" || retry_with_sudo mv "$bitcoin_conf.tmp" "$bitcoin_conf" + printf "%s\n" >> "$bitcoin_conf" # Ensure a newline exists at the end of the file + awk -v key="$key" -v value="$value" 'BEGIN {found=0} !/^#/ && $1==key {found=1; print key"="value; next} {print} END {if (!found) print key"="value}' "$bitcoin_conf" > "$bitcoin_conf.tmp" && mv "$bitcoin_conf.tmp" "$bitcoin_conf" || retry_with_sudo mv "$bitcoin_conf.tmp" "$bitcoin_conf" + awk '/./' "$bitcoin_conf" > "$bitcoin_conf.tmp" && mv "$bitcoin_conf.tmp" "$bitcoin_conf" || retry_with_sudo mv "$bitcoin_conf.tmp" "$bitcoin_conf" # Remove trailing newlines } # Pruning question and storage amount