GET_ENVIRONMENT_VARIABLE intrinsic subroutine

Standard: F77 F90 F95 F2003 F2008 F2018 Example program



NAME : scalar default Character, Intent(In);
VALUE : scalar default Character, Intent(Out);
LENGTH : scalar Integer, 16 bits or larger, Intent(Out);
STATUS : scalar Integer, 16 bits or larger, Intent(Out);
TRIM_NAME : scalar Logical, Intent(In);
ERRMSG : scalar default Character, Intent(Out).

Prior to Fortran 2018, the Integer and Logical arguments had to be of default kind.


This intrinsic subroutine retrieves the value of the environment called identified by NAME, and assigns it to the VALUE argument (if present), as if by normal character assignment.

If LENGTH is present, it is assigned the length of the environment variable's value (before its assignment to VALUE). This may be used to allocate a VALUE variable large enough to receive the full value of the argument.

If STATUS is present, it is assigned the value −1 if VALUE was present but is shorter than the environment variable, 1 if the environment variable does not exist, 2 if the processor does not support environment variables, a value greater than 2 if any other error occurs, and zero otherwise.

If TRIM_NAME is present with the value .FALSE., and the processor supports environment variable names having trailing blanks, any trailing blanks in NAME are considered to be part of the name of the environment variable. Otherwise, trailing blanks in NAME are ignored.

If an error occurs and ERRMSG is present, ERRMSG is assigned an explanatory message. Otherwise, ERRMSG is unchanged.


COMMAND_ARGUMENT_COUNT intrinsic function, GET_COMMAND intrinsic subroutine, GET_COMMAND_ARGUMENT intrinsic subroutine