If my environment-variable.ini variable is different from the environment variable, how can I modify it with the shell script?

< H2 > 1. The content in my environment-variable.ini file is < / H2 >.
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

my environment variable is

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

I want to use the shell script to judge

if the variable set in my environment-variable.ini is the same as my environment variable, the environment variable will not be changed. If it is different, change the environment variable to the variable in environment-variable.ini

< H2 > 2. How to optimize this code < / H2 >
if [ $UNIVER_USER_LOGIN ]; then -sharp  UNIVER_USER_LOGIN 
    echo ${UNIVER_USER_LOGIN}
else
    -sharp echo "export UNIVER_USER_LOGIN="xxx"" >> /etc/profile
    grep "UNIVER_USER_LOGIN" environment-variable.ini >> /etc/profile
fi
Apr.02,2021

suppose your environment-variable.ini content is like this
UNIVER_PROJECR_PORT='79000000'
I wrote one that can be realized, as you can see, there should be a better
.
-sharp!/bin/bash
while read line;do  
    eval "$line"
done < environment-variable.ini
echo $UNIVER_PROJECR_PORT

if [ $UNIVER_PROJECR_PORT == $(sed '/^UNIVER_PROJECR_PORT=/!d;s/.*=//' /etc/profile) ];then
    echo ''
else
    echo ','
    sed -i '/UNIVER_PROJECR_PORT/d' /etc/profile       -sharp
    echo "export UNIVER_PROJECR_PORT="$UNIVER_PROJECR_PORT>>/etc/profile  -sharp
fi

source /etc/profile

implementation is not important, it's too simple. Let me talk about my opinion: carefully modify / etc/ . Why? Beginners do not understand, there is no awe of this directory, it is too easy to hang up the whole system, once the files in this directory are damaged, it will affect the whole system, and even the whole system can not be started. For example, chmod/chown-R xxx / etc/

is mistakenly used for the whole / etc/. Again, I would like to emphasize that do not tamper with / etc/profile , this file is not what you think at all, and it may not meet your expectations (it is recommended that you read the startup process of shell, many shell and systems may not load this file in interactive mode). Not only that, any shell default / etc/*rc configuration should not be altered. Correct your mind first. Limited to space, I will not elaborate on the reasons. If you read more materials, you will naturally have feelings. It is a novice practice to change / etc/ indiscriminately.

how do you do that? The environment variables should not affect others as much as possible, and you really need to change them, not to change the / etc/ configuration, but to change the ~ / .* rc configuration, which only affects the current user, even if the correction will not kill the whole system, and it has been repaired.

The scope of

environment variables should be as small as possible, as small as possible to one program, not all unrelated programs will be affected, okay? So for scripts, directly write the required variables to their own script initialization, do not be disturbed by external environment variables, and do not interfere with external environment variables. The environment variable of the service is initialized by the startup script of the service. Do not change the environment variable at any time, let alone write your environment variable to / etc/ . Once you break it, the consequences will be serious

.
Menu