sourcing env output

蓝咒 提交于 2019-12-01 05:32:10
while read line; do
    declare "$line"
    # declare -x "$line"
    # export "$line"
done < env.txt

If you want to export the values to the environment, use the -x option to declare or use the export command instead.

Add the double quotes before redirecting the output to a file:

env | sed 's/=\(.*\)/="\1"/' > env.txt
while read line; do
 var="${line%=*}"
 value="${line##*=}"
 eval "$var=\"$value\""
done <env.txt
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!