Fortran Wiki
get_environment_variable

Description

Get the value of the environmental variable name.

Note that get_environment_variable need not be thread-safe. It is the responsibility of the user to ensure that the environment is not being updated concurrently with a call to the get_environment_variable intrinsic.

Standard

Fortran 2003 and later

Class

Subroutine

Syntax

call get_environment_variable(name[, value, length, status, trim_name)

Arguments

  • name - (Optional) Shall be a scalar of type character and of default kind.
  • value - (Optional) Shall be a scalar of type character and of default kind.
  • length - (Optional) Shall be a scalar of type integer and of default kind.
  • status - (Optional) Shall be a scalar of type integer and of default kind.
  • trim_name - (Optional) Shall be a scalar of type logical and of default kind.

Return value

Stores the value of name in value. If value is not large enough to hold the data, it is truncated. If name is not set, value will be filled with blanks. Argument length contains the length needed for storing the environment variable name or zero if it is not present. status is -1 if value is present but too short for the environment variable; it is 1 if the environment variable does not exist and 2 if the processor does not support environment variables; in all other cases status is zero. If trim_name is present with the value .false., the trailing blanks in name are significant; otherwise they are not part of the environment variable name.

Example

program test_getenv
  character(len=255) :: homedir
  call get_environment_variable("HOME", homedir)
  write (*,*) trim(homedir)
end program

category: intrinsics