From 0cad1cbfc01bdbb87a92f8812f292103101f6499 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Sat, 10 Oct 2020 23:37:17 +0200 Subject: support quoted string in function getperlvarfromfile() --- postfix/postfix.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/postfix/postfix.sh b/postfix/postfix.sh index 563ecd3..4a54774 100755 --- a/postfix/postfix.sh +++ b/postfix/postfix.sh @@ -144,15 +144,16 @@ catfirstfile() { cat "$configdir/$file" } -# TODO: support quoted string, and trailing comment. +# TODO: support trailing comment. getperlvarfromfile() { set -e - export var=$1 - export default=$2 + var=$1 + default=$2 file=$3 context=${4:-postfix} catfirstfile "$file" "$context" \ - | perl -nE'/^\$$ENV{"var"}\h*=\h*(\d+)/ and $s=$1; END {print length($s) ? $s : $ENV{"default"}}' + | var=$var default=$default perl -n \ + -e '/^\$$ENV{"var"}\h*=\h*(\d+)/ and $s=$1; END {print length($s) ? $s : $ENV{"default"}}' } getlinesfromfile() { -- cgit v1.2.3