From ccfb011a238be548e32fc3a1ec9477afb992b6db Mon Sep 17 00:00:00 2001 From: Christoph Date: Fri, 23 Sep 2022 18:59:21 +0200 Subject: [PATCH] read_env_from_file.sh: add function 'trim_single_quotes'. --- snippets/read_env_from_file.sh | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/snippets/read_env_from_file.sh b/snippets/read_env_from_file.sh index cd4ed38..2fb1384 100755 --- a/snippets/read_env_from_file.sh +++ b/snippets/read_env_from_file.sh @@ -40,8 +40,15 @@ trim() { trim_double_quotes() { local var="$*" - var="${var#"${var%%[!\"]*}"}" # remove leading whitespace characters - var="${var%"${var##*[!\"]}"}" # remove trailing whitespace characters + var="${var#"${var%%[!\"]*}"}" # remove leading double quotes + var="${var%"${var##*[!\"]}"}" # remove trailing double quotes + echo -n "$var" +} + +trim_single_quotes() { + local var="$*" + var="${var#"${var%%[!\']*}"}" # remove leading single quote + var="${var%"${var##*[!\']}"}" # remove trailing single quote echo -n "$var" } @@ -66,6 +73,12 @@ read_env_from_file() { # - _val="$(trim_double_quotes $_val)" + # - Remove leading / trailling double quotes + # - _val="${_val%\'}" + # - _val="${_val#\'}" + # - + _val="$(trim_single_quotes $_val)" + if [[ -n "$(trim $_key)" ]] && [[ -n "$(trim $_val)" ]] ; then export $_ENV #export $(eval echo $_ENV)