Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

As defined by the POSIX (Portable Operating System Interface) standard, operating systems store a set of values called environment variables that processes can access for getting information about the system, or configuration values for instance. Each process can set new environment variables or modify current ones, and pass them to child processes.

Each environment variable has a name. They are thus stored as name/value pairs, and retrieve through their names.

Here is an example in Bash for setting an environment variable:

Still in Bash, we retrieve the value of the environment variable as any other Bash variable:

some_value

Each programming language proposes functions to retrieve and set environment variables.

The following Python program prints the same environment variable:

import os
print(os.environ['MY_VAR'])

Here is its effect:

some_value

We can do the same in Rust:

fn main() {
  if let Ok(s) = std::env::var("MY_VAR") {
    println!("{s}");
  }
}

The effect is the same:

some_value