Lion Cipher Lab
Environment variables and the PATH
- Foundations
- Intermediate
- ~40 min
- Free · no account required
Why it matters
Every time you type a command name, something has to decide which of the thousands of programs on your machine actually runs — and that decision is made by an environment variable called PATH. Environment variables are the invisible configuration layer under the entire command line: they tell programs where your home directory is, which language and editor you prefer, where to find libraries, and — crucially — which directories to search for the very tool you just asked for. Learn them and a hundred confusing errors ('command not found' even though it IS installed; a script that works in one…
What you'll learn
- explaining what an environment variable is and how it differs from a plain shell variable
- knowing that child processes inherit the environment, and proving it
- viewing the environment (printenv, env, echo $HOME; $env:PATH, Get-ChildItem Env:)
- setting a variable for one command, exporting it, and unsetting it, in bash and PowerShell
- understanding PATH: how the shell searches it left-to-right and 'first match wins'
- locating which program a name resolves to (which, command -v, type; where.exe)
- making a variable persist (~/.bashrc, ~/.profile, /etc/environment; setx, System Properties)
- recognising PATH hijacking (MITRE ATT&CK T1574.007) and LD_PRELOAD/LD_LIBRARY_PATH injection
- knowing why secrets in environment variables leak, and the safer patterns (.env out of git, direnv, a secret manager)
Steps in this lab
- The mental model: what an environment variable actually is
- Open a terminal and view your environment
- Set, export, and unset — and prove a child inherits
- PATH: how the shell finds the program you asked for
- Make it persist — and know login vs interactive shells
- SECURITY: stage a PATH hijack (safely), then clean it up
- SECURITY: library hijacks (LD_PRELOAD) and why secrets don't belong in env
- Reflection: read it, control it, distrust it