read_env_from_file.sh: add function 'trim_single_quotes'.

This commit is contained in:
Christoph 2022-09-23 18:59:21 +02:00
parent 93a5cb9ce5
commit ccfb011a23

View File

@ -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)