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".
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".
String foo;
try {
foo = getenv("FOO");
if (foo == null) throw new Exception();
} catch (Exception e) {
foo = "none";
}
Foo : constant String :=
Ada.Environment_Variables.Value (Name => "FOO",
Default => "none");
const char * foo = getenv("FOO");
if (foo == NULL) foo = "none";
const char* tmp = std::getenv("FOO");
std::string foo = tmp ? std::string(tmp) : "none";
string foo = Environment.GetEnvironmentVariable("FOO");
if (string.IsNullOrEmpty(foo)) foo = "none";
do
foo <- catch (getEnv "FOO") (const $ pure "none" :: IOException -> IO String)
-- do something with foo
const foo = process.env.FOO ?? 'none'
(defvar foo
(uiop:getenv "FOO")
"The contents of environment variable FOO.")
foo = IIf(Environ("FOO") = "", "none", Environ("FOO"))
Dim _foo as String
Try
foo = Environment.GetEnvironmentVariable("FOO")
Catch ex as Exception
foo = "none"
End Try
String foo; try { foo = getenv("FOO"); if (foo == null) throw new Exception(); } catch (Exception e) { foo = "none"; }
String foo = System.getenv("foo"); if (foo == null) { foo = "none"; }
Foo : constant String := Ada.Environment_Variables.Value (Name => "FOO", Default => "none");
const char * foo = getenv("FOO"); if (foo == NULL) foo = "none";
(def foo (or (System/getenv "FOO") "none"))
const char* tmp = std::getenv("FOO"); std::string foo = tmp ? std::string(tmp) : "none";
string foo = Environment.GetEnvironmentVariable("FOO"); if (string.IsNullOrEmpty(foo)) foo = "none";
string foo = environment.get("FOO", "none");
var foo = Platform.environment["FOO"] ?? "none";
foo = System.get_env("FOO", "none")
Foo = os:getenv("FOO","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
foo := os.Getenv("FOO") if foo == "" { foo = "none" }
foo := cmp.Or(os.Getenv("FOO"), "none")
foo, ok := os.LookupEnv("FOO") if !ok { foo = "none" }
def foo = System.getenv('FOO') ?: 'none'
do foo <- catch (getEnv "FOO") (const $ pure "none" :: IOException -> IO String) -- do something with foo
const foo = process.env["FOO"] || "none";
const foo = process.env.FOO ?? 'none'
val foo = System.getenv("FOO") ?: "none"
(defvar foo (uiop:getenv "FOO") "The contents of environment variable FOO.")
foo = os.getenv("FOO") or "none"
$foo = getenv("FOO") ?: "none";
var foo: string; begin foo := GetEnvironmentVariable('FOO'); if (foo = '') then foo := 'none'; end.
my $foo = $ENV{FOO} // 'none';
foo = os.environ.get('FOO', 'none')
foo = getenv('FOO', 'none')
try: foo = os.environ['FOO'] except KeyError: foo = "none"
foo = ENV["FOO"]
let foo = match env::var("FOO") { Ok(val) => val, Err(_e) => "none".to_string(), };
if let Ok(tnt_root) = env::var("TNT_ROOT") { // }
let foo = env::var("FOO").unwrap_or("none".to_string());
let foo = match env::var("FOO") { Ok(val) => val, Err(_e) => "none".to_string(), };
val foo = sys.env.getOrElse("FOO", "none")
| foo | foo := CEnvironment getUserEnvironment at: 'FOO' ifAbsent: [ 'none' ].
foo = IIf(Environ("FOO") = "", "none", Environ("FOO"))
Dim _foo as String Try foo = Environment.GetEnvironmentVariable("FOO") Catch ex as Exception foo = "none" End Try