don't attempt environment substitution if no variable in file
parent
ca6f831c5d
commit
95a5f21abd
|
@ -78,15 +78,17 @@ testenv () {
|
||||||
# https://www.baeldung.com/linux/envsubst-command
|
# https://www.baeldung.com/linux/envsubst-command
|
||||||
# todo allow input file -o overwrite or to another file -f <name>
|
# todo allow input file -o overwrite or to another file -f <name>
|
||||||
env_subs_file () {
|
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 == "-e" ]] && useenv=true && shift 1
|
||||||
[[ $1 == "-o" ]] && { shift 1; fout=$1; }
|
[[ $1 == "-o" ]] && { shift 1; fout=$1; }
|
||||||
[[ $1 == "-f" ]] && { fout=$2; shift 2; }
|
[[ $1 == "-f" ]] && { fout=$2; shift 2; }
|
||||||
fin=$1; fenv=$2
|
fin=$1; fenv=$2
|
||||||
# echo useenv $useenv, fout $fout, fin $fin, fenv $fenv
|
# 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
|
[[ ! $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
|
[[ ! -f "$fin" ]] && iecho "file $fin does not exist nothing to merge with environment" && return 1
|
||||||
[[ ! $(cat $fin | grep -F "$") ]] && iecho "no variables in $fin to merge" && return 2
|
|
||||||
tout=/tmp/${USER}-mergedenvfile
|
tout=/tmp/${USER}-mergedenvfile
|
||||||
if [[ $useenv ]] && [[ -f $fenv ]]; then
|
if [[ $useenv ]] && [[ -f $fenv ]]; then
|
||||||
tout2=/tmp/${USER}-mergedenvfile2
|
tout2=/tmp/${USER}-mergedenvfile2
|
||||||
|
@ -100,6 +102,10 @@ env_subs_file () {
|
||||||
fi > $tout
|
fi > $tout
|
||||||
[[ -f $tout2 ]] && rm -f $tout2
|
[[ -f $tout2 ]] && rm -f $tout2
|
||||||
[[ $fout ]] && mv -f $tout $fout || { echo merged; cat "$tout"; }
|
[[ $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
|
# env | grep BASE
|
||||||
# # unset_env_file $2
|
# # unset_env_file $2
|
||||||
}
|
}
|
Loading…
Reference in New Issue