After this lesson, you will be able to: Configure your shell environment with confidence: the startup files, environment variables and PATH, aliases and functions, and dotfiles you version in Git so any machine feels like home.
Every command you run inherits an environment: variables, a PATH that decides which programs are found, and a shell configured by startup files. Knowing how that environment is assembled is the difference between 'command not found' being a mystery and being a thirty-second fix. This lesson also covers dotfiles, the configuration that experienced engineers carry from machine to machine.
The confusion that trips everyone up: which file does bash actually read? A login shell (when you SSH in, or log in at a console) reads `~/.bash_profile` (or `~/.profile` if that is absent). A non-login interactive shell (a new terminal tab on an already-logged-in machine) reads `~/.bashrc`. Because you want the same setup in both, the common pattern is to put everything in `~/.bashrc` and have `~/.bash_profile` source it with `[ -f ~/.bashrc ] && . ~/.bashrc`. Zsh users have the parallel `~/.zshrc`. Knowing this is why your alias works in one terminal and not another: you put it in the file that shell did not read.
PATH is just a colon-separated list of directories the shell searches, in order, to find a command.
# See your PATHecho $PATH# /usr/local/bin:/usr/bin:/bin:/home/you/.local/bin# 'command not found' almost always means the program's dir isn't on PATH.# Add a directory to PATH (put this in ~/.bashrc to make it permanent):export PATH="$HOME/.local/bin:$PATH" # prepend so it wins over system copies# Set an environment variable for the current shell + child processes:export EDITOR=vimexport NODE_ENV=production# See one variable / all of them:echo $EDITORprintenv | sort# Set a variable for ONE command only (not exported permanently):DEBUG=1 ./myscript.sh
Aliases are shortcuts for commands you type constantly. Functions handle the cases aliases can't (arguments in the middle, logic).
# Aliases (put in ~/.bashrc)alias ll='ls -lah'alias gs='git status'alias ..='cd ..'alias k='kubectl'# A function when you need an argument or logic:mkcd() {mkdir -p "$1" && cd "$1"}# usage: mkcd new-project# Reload your config after editing without opening a new terminal:source ~/.bashrc
Putting aliases in `~/.bash_profile` and wondering why a new terminal tab ignores them (tabs read `~/.bashrc`). Appending to PATH when you meant to override: `PATH="$PATH:/new"` puts your dir last, so a system binary of the same name still wins. Prepend when you want yours to win. Editing `~/.bashrc` and expecting the current shell to update without `source ~/.bashrc` or a new terminal. Setting a variable without `export`, so child processes (your scripts, your app) never see it. Committing a token or private key into a public dotfiles repo. Rotate it immediately if you do.
Pick the correct explanation.
Sign in and purchase access to unlock this lesson.