/*
content:
环境变量在Linux系统当中是一个非常重要的概念,不仅在shell当中引用环境变量的值,同时在应用程序当中也需要当前环境变量的值;这里提供了两种函数实现对系统环境变量的获取和设置
#include<stdlib.h>
char *getenv(_const char *_name);
int putenv(char *_string);
1参数说明如下:
_name:环境变量的名称
_string:环境变量的值
2 getenv的返回值
NULL:表示相关的环境变量未定义
其他:环境变量的值
3putenv的返回值
-1:表示调用失败
0:表示调用成功
date:
2014.4.21 night
*/
#include<stdlib.h>
#include<stdio.h>
int main()
{
char *s;
s=getenv("PATH");
printf("Now the PATH=%s\n",s);
if (s == NULL)
perror("getenv");
putenv("PATH=/home/root:");
puts("insert \"/home/root\" in PATH");
s=getenv("PATH");
if (s == NULL)
perror("getenv");
printf("Now the PATH=%s\n",s);
return 0;
}
linux下的系统环境变量编程
最新推荐文章于 2022-11-06 19:46:17 发布