请输入您要查询的百科知识:

 

词条 setenv
释义

setenv(改变或增加环境变量),相关函数 getenv,putenv,unsetenv。

表头文件 #include<stdlib.h>

定义函数 int setenv(const char *name,const char * value,int overwrite);

函数说明 setenv()用来改变或增加环境变量的内容。参数name为环境变量名称字符串。参数 value则为变量内容,参数overwrite用来决定是否要改变已存在的环境变量。如果overwrite不为0,而该环境变量原已有内容,则原内容会被改为参数value所指的变量内容。如果overwrite为0,且该环境变量已有内容,则参数value会被忽略。返回值 执行成功则返回0,有错误发生时返回-1。

错误代码 ENOMEM 内存不足,无法配置新的环境变量空间

范例

#include<stdlib.h>

main()

{ char * p;

if((p=getenv(“USER”)))

printf(“USER =%s\”,p);

setenv(“USER”,”test”,1);

printf(“USER=%s\”,getenv(“USEr”));

unsetenv(“USER”);

printf(“USER=%s\”,getenv(“USER”));

}

执行 USER = root USER = test USER = (null)

注释:stdlib.h 在Linux和Windows里略有不同,比如setenv函数是用在Linux里的,而在Windows里则没有setenv函数,可用putenv来代替。

____________________________________________________

Linux命令:setenv

功能说明:查询或显示环境变量。

语 法:setenv [变量名称][变量值]

补充说明:setenv为tsch中查询或设置环境变量的指令。

英文版本,欢迎翻译:

ABOUT SETENV

In C shell sets the value of an environment variable.

SYNTAX

setenv [var [word]]

var Variable of the set command. word Set instructions or information of the variable.

EXAMPLES

setenv PATH "/bin:/usr/bin:/usr/sbin:ucb/bin" - Sets the environment path to search for files in the /bin, /usr/bin, /usr/sbin and usb/bin directory.

随便看

 

百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。

 

Copyright © 2004-2023 Cnenc.net All Rights Reserved
更新时间:2025/3/4 20:13:27