linux shell template

Replace environment variables in a file with their actual values?

# config.xml

<property>
    <name>instanceId</name>
    <value>$INSTANCE_ID</value>
</property>
<property>
    <name>rootPath</name>
    <value>/services/$SERVICE_NAME</value>
</property>

envsubst < config.xml

( echo "cat <<EOF" ; cat config.xml ; echo EOF ) | sh

eval "echo \"$(cat config.xml)\""

(. .env && eval "echo \"$(cat config.xml)\"")
compgen -e | xargs -I @ sh -c 'printf "s|\$%q\>|%q|g\n" "@" "$@"' | sed -f /dev/stdin input.file > output.file

 

posted @ 2023-07-09 20:26  lvmxh  阅读(13)  评论(0编辑  收藏  举报