For beginners, there is an example.ini file in the configuration folder. I want to read the value inside and turn it into an environment variable. How can it be realized?

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``

I want to read these five values from example.ini and assign them to environment variables. How can I do that?

newcomers are not very good at writing, just have a rough demo

< H2 > continue to ask for help < / H2 >

the content of my current environment-variable.ini file is

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

I execute orders

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

the original environment variables that are not available cannot be modified, such as this environment variable UNIVER_PROJECR_PORT

.

how to optimize the code?

if there is an environment variable on the computer, you can modify the original environment variable

if there is no original, there will be no effect

< H1 > newly modified < / H1 >
-sharp!/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

Apr.02,2021

there are many methods. If you list any one, it may not be possible to
.
grep 'UNIVER_SEARCH_VIDEO' example.ini >> /etc/profile
...

source /etc/profile
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b36dd2-2c044.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b36dd2-2c044.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?