diff --git a/modules/utility/env.lib b/modules/utility/env.lib index 2b42ccb..22e1e5a 100644 --- a/modules/utility/env.lib +++ b/modules/utility/env.lib @@ -78,15 +78,17 @@ testenv () { # https://www.baeldung.com/linux/envsubst-command # todo allow input file -o overwrite or to another file -f env_subs_file () { - local fin; local fenv; local useenv; local tout; local fout; local fenv; local tout2 + local verbose; local fin; local fenv; local useenv; local tout; local fout; local fenv; local tout2 + [[ $1 == "-v" ]] && verbose=true && shift 1 [[ $1 == "-e" ]] && useenv=true && shift 1 [[ $1 == "-o" ]] && { shift 1; fout=$1; } [[ $1 == "-f" ]] && { fout=$2; shift 2; } fin=$1; fenv=$2 # echo useenv $useenv, fout $fout, fin $fin, fenv $fenv + if [[ $(cat $fin | grep -F "$") ]]; then [[ ! $fin ]] && iecho "nothing was passed to merge with environment" && return 1 - [[ ! -f "$fin" ]] && iecho "file $fin does not exit nothing to merge with environment" && return 1 - [[ ! $(cat $fin | grep -F "$") ]] && iecho "no variables in $fin to merge" && return 2 + [[ ! -f "$fin" ]] && iecho "file $fin does not exist nothing to merge with environment" && return 1 + tout=/tmp/${USER}-mergedenvfile if [[ $useenv ]] && [[ -f $fenv ]]; then tout2=/tmp/${USER}-mergedenvfile2 @@ -100,6 +102,10 @@ env_subs_file () { fi > $tout [[ -f $tout2 ]] && rm -f $tout2 [[ $fout ]] && mv -f $tout $fout || { echo merged; cat "$tout"; } + else + [[ $verbose ]] && echo "environment variable substition, no variables in $fin to merge" + fi + # env | grep BASE # # unset_env_file $2 } \ No newline at end of file