创建test.txt
查看test.txt文件内容如下:
HOME = ${HOME}
PATH = ${PATH}
API_URL = ${API_URL}
替换${HOME}为对应环境变量值,输出结果到test1.txt
envsubst '${HOME}' < test.txt > test1.txt
查看test1.txt文件内容如下:
HOME = /root
PATH = ${PATH}
API_URL = ${API_URL}
替换 H O M E 和 {HOME}和 HOME和{PATH}为对应环境变量值,输出结果到test2.txt
envsubst '${HOME},${PATH}' < test.txt > test2.txt
查看test2.txt文件内容如下:
HOME = /root
PATH = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
API_URL = ${API_URL}
替换所有的环境变量,输出结果到test3.txt
envsubst < test.txt > test3.txt
查看test3.txt文件内容如下(注意:因为API_URL环境变量不存在,所以替换为了空字符串):
HOME = /root
PATH = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
API_URL =
添加临时变量API_URL 替换所有的环境变量,输出结果到test3.txt
export API_URL =123
envsubst < test.txt > test3.txt
查看test3.txt文件内容如下
HOME = /root
PATH = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
API_URL =123