Created
November 26, 2017 00:16
-
-
Save pamtrak06/90699e1bae728a68d592fea54a30f812 to your computer and use it in GitHub Desktop.
generate list of variables from a properties file, for envsubst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# generate list of variables from a properties file | |
# form : \$VARIABLE | |
# give it to envsubst command to avoid escaping others variable in template file | |
function generate-parameters-list-for-envsubst { | |
type=$1 | |
local pts | |
local pindex | |
unset parameters | |
pts=$(cat $properties|grep export|cut -d "=" -f 1|sed "s/export //g") | |
declare -a plist | |
pindex=0 | |
for p in $(echo $pts); do | |
plist[pindex]=$(echo ${p}) | |
let "pindex = $pindex + 1" | |
done | |
parameters="" | |
for s in $(seq 0 $(( ${#plist[@]} -1 )) ); do | |
[ -n "$parameters" ] && \ | |
parameters=$(echo "$parameters,\\\$${plist[$s]}") | |
[ -z "$envp" ] && \ | |
parameters=$(echo "\\\$${plist[$s]}") | |
#echo "Element : " ${plist[$s]} | |
done | |
#echo "properties : " ${parameters} | |
echo -n "" | |
} | |
function update-from-template { | |
properties=$1 | |
template=$2 | |
result=$3 | |
generate-parameters-list-for-envsubst "$properties" | |
#echo "properties : " ${envp} | |
[ -f "${template}" ] && \ | |
. ${properties} && envsubst ${parameters} < "${template}" | tee "${result}" > /dev/null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment