鍍金池/ 問答/Linux  HTML/ 初學(xué),在configuration文件夾中有個example.ini文件,我想讀

初學(xué),在configuration文件夾中有個example.ini文件,我想讀取里面的值變成環(huán)境變量,怎么才能實現(xiàn)?

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讀取這五個值,然后賦給環(huán)境變量,怎么才能實現(xiàn)?

新人不太會寫,有個大致的demo就行

繼續(xù)求助下

我現(xiàn)在的environment-variable.ini文件內(nèi)容是

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

我執(zhí)行命令

#!/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

原來的沒有的環(huán)境變量無法修改,比如這個環(huán)境變量UNIVER_PROJECR_PORT

怎么代碼怎么優(yōu)化?

如果電腦上原來有環(huán)境變量,可以將原來的環(huán)境變量修改

如果原來沒有,就沒有效果

新改的

#!/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

圖片描述

回答
編輯回答
萢萢糖
方法很多,隨便列一個,也不一定可以
grep 'UNIVER_SEARCH_VIDEO' example.ini >> /etc/profile
...

source /etc/profile
2017年8月19日 05:53