linux shell template

发布时间 2023-07-09 20:32:22作者: lvmxh

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