How to set and get an environment variable in C on Linux?
如何在Linux上的 C中设置和获取环境变量?
You can use the setenv
and getenv
POSIX APIs to set and get environment variables.
您可以使用setenv
和getenv
POSIX API来设置和获取环境变量。
To add or change environment variable:
要添加或更改环境变量:
#include <stdlib.h>
int setenv(const char *envname, const char *envval, int overwrite);
To get value of an environment variable:
要获取环境变量的值:
#include <stdlib.h>
char *getenv(const char *name);
Answered by anonymous.
匿名回答。
翻译自: https://www.systutorials.com/how-to-set-and-get-an-environment-variable-in-c-on-linux/