Skip to content
BENIBIX Learn

Environment Variable

Infrastructure⌨️ Linux & the Command LineCommand Line

Also known as Env Var, Environment Variables, ENV

A named value that the shell gives to each program it starts.

Think of it like

Think of it like a sticky note on the fridge. Anyone in the house can read it.

Example

Jack's app reads its database password from an environment variable. The code stays the same on Jack's laptop and on the server.

Why it matters

It keeps settings and secrets out of the code. The same app can then run anywhere.

Definition

An environment variable is a named value that the shell hands to every program it starts. Programs read it to learn settings, like which folder is home or which key to use. You set one with a line like export NAME=Emma. Its name is usually written in capital letters. Secrets such as passwords are often passed this way, so they never sit in the code.

Example code

console
$ export NAME=Emma
$ echo "Hi $NAME"
Hi Emma
Set a value called NAME, then read it back.

Common mistake

Setting it in one terminal and expecting another to see it. Each shell has its own copy.

Key takeaways

  1. 1
    Named value. Usually in capitals.
  2. 2
    Handed down. Every program it starts sees it.
  3. 3
    Keeps secrets out. Not written in the code.

Learn it properly