From 05c9c5136d400ff90cbbe554a539328a1c585d1a Mon Sep 17 00:00:00 2001 From: deicidus Date: Fri, 16 Jun 2023 03:52:28 -0700 Subject: [PATCH] better variable parsing --- spells/menu/bitcoin/configure-bitcoin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spells/menu/bitcoin/configure-bitcoin b/spells/menu/bitcoin/configure-bitcoin index 89495a0..c1bbcf5 100755 --- a/spells/menu/bitcoin/configure-bitcoin +++ b/spells/menu/bitcoin/configure-bitcoin @@ -45,7 +45,7 @@ modify_bitcoin_conf() { local key=$1 local value=$2 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 -v key="$key" -v value="$value" 'BEGIN {OFS=FS="="; found=0} {gsub(/^[ \t]+|[ \t]+$/, "", $1)} !/^#/ && $1==key {found=1; print key"="value; next} {print $1"="$2} 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 }