Bash: envsubst

将环境变量传递给文件
更新于: 2023-10-11 13:35:23

welcome.txt

This is $FOO and this $BAR

usage

export FOO=foo export BAR=bar
# 全量替换
envsubst < welcome.txt
This is foo and this bar

# 部分替换
envsubst '$FOO' < welcome.txt
This is foo and this $BAR

# 多个变量
envsubst '$FOO,$BAR' < welcome.txt
This is foo and this bar

参考