set one or more environment variables
#include <env.h>
int setenv( const char *name,
const char *newvalue,
int overwrite );
The environment list consists of a number of environment names, each of which has a value associated with it.
The setenv() function searches the environment list for an entry of the form name=value. If no such string is present, setenv() adds an entry of the form name=newvalue to the environment list. Otherwise, if the overwrite argument is non-zero, setenv() either will change the existing value to newvalue, or will delete the string name=value and add the string name=newvalue.
If the newvalue pointer is NULL, all strings of the form name=value in the environment list will be deleted.
The value of the pointer environ may change across a call to the setenv() function.
The setenv() function makes copies of the strings associated with name and newvalue.
The matching is case-sensitive; all lowercase letters are treated as different from uppercase letters.
To assign a string to a variable and place it in the environment list, use the export command, as follows:
export INCLUDE=/usr/include
To see what variables are in the environment list, and their current assignments, type the export command without any arguments. The output will be like the following:
SHELL=ksh
TERM=qnx
LOGNAME=fred
PATH=:/bin:/usr/bin
HOME=/home/fred
INCLUDE=/usr/include
LIB=/usr/lib
clearenv(), errno, exec... functions, getenv(), putenv(), _searchenv(), searchenv(), spawn... functions, system()
The following changes the string assigned to INCLUDE and then displays the new string.
#include <stdio.h>
#include <stdlib.h>
#include <env.h>
void main()
{
char *path;
if( setenv( "INCLUDE",
"/usr/include:/home/fred/include",
1 ) == 0 )
if( (path = getenv( "INCLUDE" )) != NULL )
printf( "INCLUDE=%s\n", path );
}
POSIX 1003.1
All (except Netware, DOS/PM)