Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
- Ada
- C
- Clojure
- C++
- C#
- D
- Dart
- Elixir
- Erlang
- Fortran
- Go
- Go
- Go
- Groovy
- Haskell
- JS
- JS
- Java
- Java
- Kotlin
- Lisp
- Lua
- PHP
- Pascal
- Perl
- Python
- Python
- Python
- Ruby
- Rust
- Rust
- Rust
- Rust
- Scala
- Smalltalk
- VB
- VB
Foo : constant String :=
Ada.Environment_Variables.Value (Name => "FOO",
Default => "none");
const char * foo = getenv("FOO");
if (foo == NULL) foo = "none";
Returns a pointer to the value or NULL
(def foo
(or (System/getenv "FOO") "none"))
const char* tmp = std::getenv("FOO");
std::string foo = tmp ? std::string(tmp) : "none";
If environment variable was not found, std::getenv returns nullptr
string foo = Environment.GetEnvironmentVariable("FOO");
if (string.IsNullOrEmpty(foo)) 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
do
foo <- catch (getEnv "FOO") (const $ pure "none" :: IOException -> IO String)
-- do something with foo
const foo = process.env.FOO ?? 'none'
The nullish colaescing operator (??) is available in ES2020 onwards. It ensures that if the FOO environment variable is the empty string, foo isn't set to 'none'.
const foo = process.env["FOO"] || "none";
String foo;
try {
foo = getenv("FOO");
if (foo == null) throw new Exception();
} catch (Exception e) {
foo = "none";
}
"... On UNIX systems the alphabetic case of name is typically significant, while on Microsoft Windows systems it is typically not."
String foo = System.getenv("foo");
if (foo == null) {
foo = "none";
}
(defvar foo
(uiop:getenv "FOO")
"The contents of environment variable FOO.")
Common Lisp doesn't have a built-in way to examine environment variables, so we rely on the portability library UIOP. I believe all currently maintained implementations include UIOP as part of ASDF. The REQUIRE form loads ASDF, and thus UIOP.
If an environment variable is present and empty then FOO will be an empty string. "FOO" is not present on my system, so FOO gets NIL.
If an environment variable is present and empty then FOO will be an empty string. "FOO" is not present on my system, so FOO gets NIL.
foo = os.getenv("FOO") or "none"
foo = ENV["FOO"]
Returns nil if "FOO" is absent.
val foo = sys.env.getOrElse("FOO", "none")
| foo |
foo := CEnvironment getUserEnvironment at: 'FOO' ifAbsent: [ 'none' ].
foo = IIf(Environ("FOO") = "", "none", Environ("FOO"))
https://docs.microsoft.com/en-us/office/vba/Language/Reference/user-interface-help/iif-function
Dim _foo as String
Try
foo = Environment.GetEnvironmentVariable("FOO")
Catch ex as Exception
foo = "none"
End Try