#include <stdlib.h>
#include <stdio.h>
extern char** environ;
int main(){
int i;
for(i=0;environ[i];i++){
printf("%s\n",environ[i]);
}
printf("env:HOME:%s\n",getenv("HOME"));
setenv("username","teanee",1);
printf("env:username:%s\n",getenv("username"));
if(!unsetenv("username"))
printf("clear evn.username\n");
if(!clearenv()){
printf("clear all env, $HOME:%s\n",getenv("HOME"));
}
putenv("username=teanee");
printf("env.username:%s\n",getenv("username"));
putenv("username=bycool");
printf("env.username:%s\n",getenv("username"));
return 0;
}
1.extern char** envrion全局变量
2.char *getenv(const char *name); 获得name环境变量
3.int setenv(const char *name, const char *value, int overwrite);overwrite为0不覆盖
4.int unsetenv(const char *name);删除name环境变量
5.int clearenv(void); 清除所有环境变量
6.int putenv(char *string);添加或修改一个环境变量.string格式:name=value.
网友评论