1、我的environment-variable.ini文件内的内容是
export UNIVER_USER_LOGIN='http://127.0.0.1/api/login'
export UNIVER_SEARCH_ORDINARY='http://127.0.0.1/api/search/common'
export UNIVER_SEARCH_LABEL='http://127.0.0.1/api/search/common'
export UNIVER_SEARCH_VIDEO='http://127.0.0.1/api/search/common'
export UNIVER_TASK_MANAGER='http://127.0.0.1/api/task/manager'
export UNIVER_PROJECR_URL='167.210.220.11'
export UNIVER_PROJECR_PORT=667777760011
我的环境变量是
export UNIVER_MONGO_URL='mongodb://10.10.0.49:27017'
export UNIVER_USER_LOGIN='http://demo.kube.univer/api/login'
export UNIVER_SEARCH_ORDINARY='http://demo.kube.univer/api/search/common'
export UNIVER_SEARCH_LABEL='http://127.0.0.1/api/search/common'
export UNIVER_SEARCH_VIDEO='http://127.0.0.1/api/search/common'
export UNIVER_TASK_MANAGER='http://127.0.0.1/api/task/manager'
export UNIVER_PROJECR_URL='67.110.220.11'
export UNIVER_PROJECR_PORT=6677
我希望用shell 脚本判断
如果我的environment-variable.ini中所设置的变量跟我的环境变量相同就不改变环境变量,如果不相同的话,将环境变量修改成environment-variable.ini中的变量
2、这段代码怎么优化
if [ $UNIVER_USER_LOGIN ]; then # 如果 UNIVER_USER_LOGIN 存在
echo ${UNIVER_USER_LOGIN}
else
# echo "export UNIVER_USER_LOGIN='xxx'" >> /etc/profile
grep 'UNIVER_USER_LOGIN' environment-variable.ini >> /etc/profile
fi
假设你的environment-variable.ini内容是这样的
我写了一个,能实现,你可以看看,应该有更好的