get_environment_variable

Date:

02-07-2023

NAME

get_environment_variable - Returns the value of an environment variable

SYNOPSIS

call get_environment_variable(name[, value, length, istatus, trim_name])

STANDARDS

Fortran 2008

DESCRIPTION

The get_environment_variable intrinsic subroutine returns the value of the specified environment variable. This intrinsic accepts these arguments:

name

Specifies the name of the environment variable whose value you want to retrieve. This argument must be a scalar of type default character.

value

Returns the value given to the name environment variable. If the environment variable does not exist or does not have a value, value is filled with blanks. This argument must be a scalar of type default character.

length

Returns the length of the value assigned to environment variable name in bytes; otherwise, it returns zero. This argument must be a scalar of type default integer.

istatus

Returns the condition of the data contained in the value and length arguments. istatus must be a scalar of type default integer. One of these values is returned:

0

Environment variable name exists and either has or has no value.

1

Environment variable name does not exist.

-1

The returned value was truncated and the length argument returns the length of the truncated value.

trim_name

Indicates that the trailing spaces in value are part of the environment variable’s name or not a part of it. Set to true if they are and false they are not. This argument must be a scalar of type logical.

EXAMPLES

The following example can be inserted into your command to return the value of the $SHELL environment variable:

program getvalue
   integer length, istatus
   character :: name*80, value*80
   logical :: trim_name = .false.
   name = 'SHELL'
   call get_environment_variable(name,value,length,istatus,trim_name)
   print *, 'istatus = ', istatus
   if (istatus .eq. 0) then
      print *,' environment var ',trim(name),' = ',value
   endif
end program getvalue

SEE ALSO

get_command(3i), get_command_argument(3i), command_argument_count(3i)