>_How the Terminal Works · Lesson 4 of 7

Environment Variables & Shell Startup

Why does PATH exist in every window? What is .bashrc actually for? Environment variables are the shell's inheritance system — settings that flow parent to child, window to program.

Bash
# Every process carries a set of KEY=value strings:
env | head             # see yours
echo $HOME             # /home/you
echo $USER $LANG

# Shell variable vs environment variable:
color=blue             # shell-only: children can't see it
export COLOR=blue      # environment: inherited by children

# Prove inheritance:
export MY_FLAG=hello
bash -c 'echo $MY_FLAG'    # hello — child got a COPY
MY_FLAG=changed bash -c 'echo $MY_FLAG'  # one-off override

# Copies, not links — child changes never flow back up.
# This is why 'export PATH=...' in one window
# does nothing for other windows.

Programs read the environment for configuration: EDITOR tells git which editor to open, HOME tells everything where your files live, NODE_ENV switches app behavior, API keys arrive in CI this way. It's the universal config channel — no files, no flags, inherited automatically.

Bash
# Startup files — run automatically, this is where
# your customizations live:
#
#   bash:  ~/.bashrc   (each interactive shell)
#          ~/.bash_profile  (login shells; usually sources .bashrc)
#   zsh:   ~/.zshrc
#
# Typical contents:
export PATH="$HOME/.local/bin:$PATH"   # add your tools dir
export EDITOR=vim
alias gs='git status'
alias ll='ls -alF'

# Apply edits to the CURRENT shell (else: new window):
source ~/.bashrc
✦ Tip
Now installer instructions make sense: 'add this line to your .bashrc' means 'make this environment change happen in every future shell'. And when a tool works in one terminal but not another — diff their env output; it's almost always PATH.