初学,在configuration文件夹中有个example.ini文件,我想读取里面的值变成环境变量,怎么才能实现?

发布于 2022-09-07 20:13:02 字数 2378 浏览 39 评论 0

example.ini

UNIVER_SEARCH_VIDEO=http://127.0.0.1/api/search/common
UNIVER_MONGO_URL=mongodb://127.0.0.1
UNIVER_SEARCH_LABEL=http://127.0.0.1api/search/common
UNIVER_USER_LOGIN=http://127.0.0.1/api/login
UNIVER_TASK_MANAGER=http://127.0.0.1/api/task/manager`请输入代码`

我希望从example.ini读取这五个值,然后赋给环境变量,怎么才能实现?

新人不太会写,有个大致的demo就行

继续求助下

我现在的environment-variable.ini文件内容是

UNIVER_USER_LOGIN=http://127.0.0.1/api/login
UNIVER_SEARCH_ORDINARY=http://127.0.0.1api/search/common
UNIVER_SEARCH_LABEL=http://127.0.0.1/api/search/common
UNIVER_SEARCH_VIDEO=http://127.0.0.1/api/search/common
UNIVER_TASK_MANAGER=http://127.0.0.1/api/task/manager
UNIVER_PROJECR_URL=567.110.220.11
UNIVER_PROJECR_PORT=667777760011

我执行命令

#!/bin/bash

grep 'UNIVER_USER_LOGIN' environment-variable.ini >> /etc/profile
grep 'UNIVER_SEARCH_LABEL' environment-variable.ini >> /etc/profile
grep 'UNIVER_SEARCH_VIDEO' environment-variable.ini >> /etc/profile
grep 'UNIVER_SEARCH_VIDEO' environment-variable.ini >> /etc/profile
grep 'UNIVER_TASK_MANAGER' environment-variable.ini >> /etc/profile
grep 'UNIVER_PROJECR_URL' environment-variable.ini >> /etc/profile
grep 'UNIVER_PROJECR_PORT' environment-variable.ini >> /etc/profile


source /etc/profile

:<<!
if [ $UNIVER_SEARCH_VIDEO ]; then
    echo ${UNIVER_SEARCH_VIDEO}
else
    echo "找不到"
fi

原来的没有的环境变量无法修改,比如这个环境变量UNIVER_PROJECR_PORT

怎么代码怎么优化?

如果电脑上原来有环境变量,可以将原来的环境变量修改

如果原来没有,就没有效果

新改的

#!/bin/bash

grep 'UNIVER_USER_LOGIN' environment-variable.ini >> /etc/profile
grep 'UNIVER_SEARCH_LABEL' environment-variable.ini >> /etc/profile
grep 'UNIVER_SEARCH_VIDEO' environment-variable.ini >> /etc/profile
grep 'UNIVER_SEARCH_VIDEO' environment-variable.ini >> /etc/profile
grep 'UNIVER_TASK_MANAGER' environment-variable.ini >> /etc/profile
grep 'UNIVER_PROJECR_URL' environment-variable.ini >> /etc/profile
echo "UNIVER_PROJECR_PORT='xxx'" >> /etc/profile
sed -i '/UNIVER_PROJECR_PORT/s/xxx/79000000/g' /etc/profile
grep 'UNIVER_PROJECR_PORT' environment-variable.ini >> /etc/profile

source /etc/profile

图片描述

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

老街孤人 2022-09-14 20:13:02
方法很多,随便列一个,也不一定可以
grep 'UNIVER_SEARCH_VIDEO' example.ini >> /etc/profile
...

source /etc/profile
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文