COHERENT manpages
This page displays the COHERENT manpage for getenv() [Read environmental variable].
List of available manpages
Index
getenv() -- General Function (libc)
Read environmental variable
#include <stdlib.h>
char *getenv(VARIABLE) char *VARIABLE;
A program may read variables from its environment. This allows the program
to accept information that is specific to it. The environment consists of
an array of strings, each having the form VARIABLE=VALUE. When called with
the string VARIABLE, getenv() reads the environment, and returns a pointer
to the string VALUE.
Example
This example prints the environmental variable PATH.
#include <stdio.h>
#include <stdlib.h>
main()
{
char *env;
extern char *getenv();
if ((env = getenv("PATH")) == NULL) {
printf("Sorry, cannot find PATH\n");
exit(1);
}
printf("PATH = %s\n", env);
}
See Also
environmental variables,
envp,
exec,
libc,
putenv(),
sh,
stdlib.h
ANSI Standard, §7.10.4.4
POSIX Standard, §4.6.1
Diagnostics
When VARIABLE is not found or has no value, getenv() returns NULL.




