Skip to main content

Environment Variables and Shell Startup

PRIMARY CONCEPT - Core mastery required for cluster advancement

Concept Cluster Navigation

Cluster 03: Environment Automation

What This Concept Is

Your shell session starts with configuration. Environment variables, shell variables, startup files, aliases, and functions define how commands are found and how tools behave.

Why It Matters Here

Many environment problems are really startup-file problems:

  • command not found
  • wrong Python or Node version
  • aliases not loading
  • prompt changes missing
  • tools behaving differently across sessions

If you understand shell startup and variables, these problems become diagnosable instead of mysterious.

Concrete Example

Suppose you added a script to ~/bin but typing its name still gives command not found.

Likely cause: your PATH does not include ~/bin, or the change lives in a startup file that the current shell did not load.

Typical fix:

export PATH="$HOME/bin:$PATH"
source ~/.bashrc

Then verify:

echo "$PATH"
which your-script-name

Common Confusion / Misconception

Common beginner confusion:

  • mixing shell variables with environment variables
  • editing the wrong startup file
  • changing a file but forgetting to reload it
  • not understanding that child processes inherit environment variables

How To Use It

Commands and ideas to own:

echo "$HOME"
echo "$PATH"
printenv
export NAME=value
unset NAME
source ~/.bashrc
which python
type cd

Basic startup-file rules:

  • put environment variables and PATH changes in your shell startup config
  • reload the file with source if you need the current session to pick up changes
  • keep changes in your home directory, not global system files, unless you intentionally manage the whole system

Check Yourself

  1. Can you explain what PATH does in one sentence?
  2. Do you know how to tell whether a command is an alias, builtin, or executable?
  3. If a config change does not seem to apply, do you know what to inspect first?

Mini Drill or Application

Complete this in your own environment:

  1. Print PATH
  2. Add one harmless alias or function
  3. Add one new path entry or exported variable
  4. Reload the startup file
  5. Verify the change in the current shell

Then open a new terminal and verify it persists.

Read this only if stuck

  • Start with Reference and Selective Reading for the curated shell, editor, and environment sources.
  • If you need a second explanation, skim Missing Semester and then retry the commands from this page.
  • Prefer one concrete terminal action over more passive reading.

Video and Lecture References

Depth Path

Professional Integration

Environment control is one of the clearest markers of engineering maturity. The ability to explain PATH, exported variables, and startup behavior is what separates "I install tools" from "I manage a working development environment."

Cluster Integration Check

  • You can explain PATH
  • You can export a variable and verify it
  • You know how to reload your shell configuration
  • You can diagnose why a command is or is not being found

Ready to advance: Continue to Dotfiles and Reproducible Setup.