Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Fortran

Idiom #205 Get an environment variable

Read an environment variable with the name "FOO" and assign it to the string variable foo. If it does not exist or if the system does not support environment variables, assign a value of "none".

  call get_environment_variable ("FOO", length=n, status=st)
  if (st /= 0) then
    foo = "none"
  else
    allocate (character(len=n) :: foo)
    call get_environment_variable ("FOO", value=foo)
  end if 
with Ada.Environment_Variables;
Foo : constant String :=
      Ada.Environment_Variables.Value (Name    => "FOO",
                                       Default => "none");

New implementation...
< >
tkoenig