Lesson 4 of 7 · 0 of 1 exercises solved
Environment Variables & Shell Startup
Learn what are, how they pass from a to the programs it starts, and what startup files like .bashrc are for.
# 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 which editor to open, HOME tells everything where your files live, NODE_ENV switches app behavior, keys arrive in CI this way. It is a common way to configure programs without files or flags, and child processes inherit it automatically.
# 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 ~/.bashrcPractice
Shell exercise
3 checksEnvironment variables
Variables live in the environment. Print your HOME and USER, create a variable EDITOR set to nano with export, and confirm it shows up in env.
Practice shell — type help to see what is available.
Finished reading?1 exercise still open. You can come back to it later.
Tip: use the ← and → keys to move between lessons.