Objective

Customize your shell with aliases and environment variables, understand how the shell startup sequence works, and make changes persistent.

Tools & Technologies

  • alias
  • export
  • env
  • printenv
  • source
  • ~/.bashrc

Key Commands

alias ll='ls -lah'
export PATH=$PATH:/new/dir
env | grep HOME
source ~/.bashrc

Architecture Overview

sequenceDiagram participant T as Terminal Opens participant SYS as /etc/profile participant BASH as ~/.bash_profile participant RC as ~/.bashrc participant SH as Interactive Shell T->>SYS: Login shell reads system profile SYS-->>T: System-wide variables set T->>BASH: Read ~/.bash_profile BASH->>RC: Sources ~/.bashrc RC-->>SH: Aliases + functions loaded SH-->>T: Prompt ready

Step-by-Step Process

01
Environment Variables

Variables stored in the shell environment. Use export to make them available to child processes.

# View all environment variables
env
printenv

# View specific variable
echo $HOME
echo $PATH
printenv EDITOR

# Set variable (current shell only)
MYVAR='hello'
# Export to child processes
export MYVAR='hello'
export PATH=$PATH:/usr/local/myapp/bin
02
Aliases

Aliases are shorthand for longer commands. Define them in ~/.bashrc for persistence.

# Temporary alias (this session only)
alias ll='ls -lah'
alias ..='cd ..'
alias grep='grep --color=auto'
alias update='sudo apt update && sudo apt upgrade'

# Remove alias
unalias ll

# List all aliases
alias
03
Make Changes Persistent

Add aliases and variables to ~/.bashrc (interactive shells) or ~/.bash_profile (login shells).

# Edit .bashrc
nano ~/.bashrc

# Add at the bottom:
alias ll='ls -lah'
alias gs='git status'
export EDITOR=vim
export HISTSIZE=10000

# Apply without restarting
source ~/.bashrc
# or
. ~/.bashrc

Challenges & Solutions

  • Variables without export are not visible to child processes
  • Typo in .bashrc can break shell startup — test before saving

Key Takeaways

  • Use ~/.bashrc for interactive shell config, ~/.bash_profile for login shells
  • Alias expansion happens before command execution — alias rm='rm -i' adds safety net