diff options
author | Jonas Smedegaard <dr@jones.dk> | 2020-10-10 23:37:17 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2020-10-10 23:37:17 +0200 |
commit | 0cad1cbfc01bdbb87a92f8812f292103101f6499 (patch) | |
tree | 94b64b5d64daf9263f8ab62dbe904fbb7f89ba00 | |
parent | 85585621463e4511e265a4a8d6604993bfd3b5e1 (diff) |
support quoted string in function getperlvarfromfile()
-rwxr-xr-x | postfix/postfix.sh | 9 |
1 files 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() { |