.TH getenv() "" "" "General Function (libc)"
.PC "Read environmental variable"
.B "#include <stdlib.h>"
\fBchar *getenv(\fIVARIABLE\^\fB) char *\fIVARIABLE\^\fB;\fR
.PP
A program may read variables from its
.IR 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
.IR "VARIABLE=VALUE" .
When called with the string
.IR VARIABLE ,
.B getenv()
reads the environment, and returns a pointer to the string
.IR VALUE .
.SH Example
This example prints the environmental variable
.BR PATH .
.DM
#include <stdio.h>
#include <stdlib.h>
.DE
.DM
main()
{
	char *env;
	extern char *getenv();
.DE	
.DM
	if ((env = getenv("PATH")) == NULL) {
		printf("Sorry, cannot find PATH\en");
		exit(1);
	}
	printf("PATH = %s\en", env);
}
.DE
.SH "See Also"
.Xr "environmental variables," environme
.Xr "envp," envp
.Xr "exec," exec
.Xr "libc," libc
.Xr "putenv()," putenv
.Xr "sh," sh
.Xr "stdlib.h" stdlib.h
.br
\*(AS, \(sc7.10.4.4
.br
\*(PX Standard, \(sc4.6.1
.SH Diagnostics
When
.I VARIABLE
is not found or has no value,
.B getenv()
returns NULL.
