

getenv()                 General Function                getenv()




Read environmental variable

cchhaarr *ggeetteennvv(_V_A_R_I_A_B_L_E) cchhaarr *_V_A_R_I_A_B_L_E;

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>

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, sh

***** Diagnostics *****

When VARIABLE is not found or has no value, getenv returns NULL.

















COHERENT Lexicon                                           Page 1


