centos learning: understanding the environment variable temporary, permanent

临时变量操作

name=dai
echo $name
name=$name"chen"  //连接
echo $name
#include <stdio.h>

int main(int argc,char *argv[]){

        char *getResult=getenv("PATH");
        printf(" PATH is %s\n",getResult);
        int i;
        if(argc == 2){
                //      printf("%s",argv[1]);
                if(strcmp(argv[1],"-version") == 0){
                        printf("god version is 1.0\n");
                }
                else{
                        printf("%s \n",argv[1]);
                }
                return 0;
        }
}
#include <stdio.h>
#include <stdlib.h>

int main(int argc,char *argv[]){
        putenv("name=daichens");    //god.c进程下设置环境变量
        char *getResult=getenv("name");
        printf("PATH is %s\n",getResult);
        if(argc==2)
        {
                if(strcmp(argv[1],"-version")==0)
                {
                        printf("god version is 1.0\n");
                }
                else
                {
                        printf("%s \n",argv[1]);
                }
                return 0;
        }
}

Under the same process temporary variable is accessible
to different processes can not access the temporary variables

在etc/profile最后加上永久环境变量.
GOD_PATH=/god
export GOD_PATH

source /etc/profile

etc / profile file is one of the first to run when bash starts

Published 65 original articles · won praise 3 · views 50000 +

Guess you like

Origin blog.csdn.net/web_orange/article/details/73557387