Environ environment variable operation function under Linux

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.