1. extern char **environ; global variables
All the values of the Linux environment variables are stored in this global variable.
Example: Print out all the environment variables
#include <stdio.h>#include <stdlib.h>extern char **environ;Import this global variableint main (int argc, char* agrv[]) {int i;for (i=0;environ[i];i++) {printf ("%s\n", Environ[i]);}return 0;}
2. getenv get the value of an environment variable
Char *getenv (const char *name); //name Name, environment variable is the form of a key-value pair, and its value is obtained by name
Return value: Returns the corresponding value successfully, failing to return null.
3. setenv setting the value of the environment variable
int setenv (const char *name, const char *value, int overwrite); //Set, name key, value, overwrite if existing overwrite
Return value: 0 successfully returned, failure returned-1.
int unsetenv (const char *name);Clears the value of the environment variable for the specified name
Return value: 0 successfully returned, failure returned-1.
int clearenv (void); //Clear All environment variables
The return value returned successfully to 0, and the failure returned non 0.
int putenv (char *string); //change or add an environment variable, in the form of a string parameter Name=value
The return value returned successfully to 0, and the failure returned non 0.
Linux environment variable operation function