Logo

Programming-Idioms

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

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".

with Ada.Environment_Variables;
Foo : constant String :=
      Ada.Environment_Variables.Value (Name    => "FOO",
                                       Default => "none");
#include <stdlib.h>
const char * foo = getenv("FOO");
if (foo == NULL) foo = "none";

Returns a pointer to the value or NULL

New implementation...
< >
tkoenig