LINUX / A CONCEPT NOTE

Environment Variables

where config hides

~60 sec read

Overview · mechanism
pitfall · examples

01 / THE SHORT VERSION

The idea in a few sentences.

Environment variables are key-value pairs stored in the shell process. Sub-processes inherit these variables, making them ideal for passing configuration and secrets.

02 / FOLLOW THE MECHANISM

How variable inheritance flows

  1. Shell

    user defines a variable: export DB_HOST='10.0.1.5'.

  2. Fork

    shell spawns a child process (like a web app).

  3. Inherit

    child process copies the environment variables block.

  4. Access

    app reads DB_HOST to establish database connection.

04 / COMMAND NOTES

Read the command, then the result.

Inspect the flags and arguments before trying an example. Snippets can need local setup, replacement values, or resources in your own environment.

EXAMPLE 01 · REFERENCE

view the value of a specific environment variable

printenv DB_HOST

EXAMPLE 02 · REFERENCE

define and export a variable for child processes

export DB_PORT=5432

Explore command anatomy in the CLI lab