#include <stdio.h>int main (int argc,char *argv[],char **envptr) { int i=0; for (i=0; envptr[i]!=null; i++) printf ("%s\n", Envptr[i]); return 0;}
The main function is the entry function of the program, int main (int argc,char *argv[]);
ARGC is the number of program parameters, argv save parameters
The same functionality as the program below
#include <stdio.h> #include <stdlib.h> #include <unistd.h>extern char **environ;int main (int argc, Char **argv) { char **env = environ; while (*env) { printf ("%s\n", *env); env++; } printf ("Home:%s\n", getenv ("Home")); return 0;}
The functions related to environment variables in C programs are as follows
#include <stdlib.h>char *getenv (const char *name); int setenv (const char *name, const char *value, int overwrite); int Putenv (char *string); int unsetenv (const char *name); int clearenv (void);
Reference Man 7 environ
Environ global variable Save user environment, above function can get, set, delete, empty environment variable
The shell command for the response is as follows
echo $PATH print PATH environment variable
Export path= $PATH:./ Set Environment variables
unset PATH Delete environment variable
Env Display all environment variables
Environ environment variable operation function under Linux