Shell Configuration & Environment

“It works on my machine.” The reason is almost always the environment — variables, paths, settings.

Environment Variables

echo $HOME
echo $USER
echo $SHELL
echo $PWD
env
printenv PATH
MY_VAR="hello"        # Local variable
export MY_VAR="hello" # Exported to child processes

$PATH — The Most Important Variable

Colon-separated list of directories the shell searches for commands.

echo $PATH
export PATH="/opt/new-tool/bin:$PATH"

Key takeaway: When a command works in one terminal but not another, check $PATH.

Shell Config Files

File When it runs
~/.bashrc Every interactive bash shell
~/.bash_profile Login shells
~/.zshrc Every interactive zsh shell
~/.profile Login shells, generic
nano ~/.bashrc
source ~/.bashrc

Aliases

alias ll='ls -la'
alias gs='git status'
alias gp='git pull'
alias ..='cd ..'
alias ...='cd ../..'
alias myserver='ssh alice@192.168.1.50'
alias activate='source venv/bin/activate'

Shell Functions

mkcd() { mkdir -p "$1" && cd "$1"; }
backup() {
    cp "$1" "$1.bak.$(date +%Y%m%d)"
    echo "Backed up to $1.bak.$(date +%Y%m%d)"
}

Shell History & Navigation Shortcuts

history
history | grep docker
Ctrl+R  # Reverse search
!!      # Repeat last command

Keyboard shortcuts: Ctrl+A (beginning), Ctrl+E (end), Ctrl+U (delete to start), Ctrl+K (delete to end), Ctrl+W (delete word), Ctrl+L (clear), Ctrl+R (search history — most underused shortcut).

Customizing Your Prompt ($PS1)

export PS1='\u@\h:\w\$ '

Tip: Look into starship (starship.rs) for a richer prompt.

Try It Yourself

Add aliases and functions to ~/.bashrc, source it, then test ll, .., and mkcd. Verify a PATH change with echo $PATH | grep mytools.

Quiz

You install a tool in /home/alice/tools/bin but get “command not found”. Why?

Answer

B) The directory is not in $PATH. Add export PATH="/home/alice/tools/bin:$PATH" to ~/.bashrc.