Linux for Developers
/Intermediate
Environment Variables
Definition
Dynamic-named values that can affect the way running processes will behave on a computer. They are part of the environment in which a process runs.
Explain Like I'm New
Sticky notes stuck to your computer that programs can read. For example, a sticky note named `USER` says 'bob'. When a program needs to know who is using it, it reads the note.
Real World Example
A Node.js application needs to connect to a database. Instead of hardcoding the password into the code (a major security risk), the code looks for an environment variable named `DB_PASSWORD`. The server admin sets `export DB_PASSWORD='supersecret'`, and the app securely connects.
Common Use Cases
- •Passing secrets to applications
- •Configuring system paths
Interview Questions
basic
- What extremely important environment variable tells Linux exactly which folders to search when you type a command like `ls` or `python`?
intermediate
- What is the difference between setting a variable with `MY_VAR="hello"` versus `export MY_VAR="hello"`?