Introduction
This lesson is about making the shell feel like your workspace instead of a generic terminal.
The main question is:
How do you make Bash start with the right variables, aliases, functions, and defaults for a user or for the whole system?
What you should be able to do after this lesson:
- Understand the difference between global and user shell startup files.
- Set environment variables such as
PATH. - Use
export,set,unset,source, aliases, and shell functions. - Understand what
/etc/skel/is for. - Know where Bash reads login and interactive settings from.
Big Idea: The Shell Environment Comes from Files Plus the Current Session
When a shell starts, it does not begin from nothing. It reads configuration files and builds an environment for the user.
At beginner level, keep this picture in your head:
global files -> user files -> current shell session -> child processes
That explains why:
- one user can have custom settings without changing the whole system
- a temporary variable can exist only in the current shell
- an exported variable can reach child processes
Global vs User Configuration
Global files
These affect many users.
Common examples:
/etc/profile
/etc/bash.bashrc
Use them when:
- the setting should apply system-wide
- you want new users to inherit a common shell behavior
User files
These affect one user's shell.
Common examples:
~/.bash_profile
~/.bash_login
~/.profile
~/.bashrc
~/.bash_logout
Simple beginner idea:
- login shell files = settings when you log in
~/.bashrc= settings for interactive Bash shells
Login Shell vs Interactive Shell
This is where many people get confused.
Login shell
Typical examples:
- text console login
- SSH login
- some desktop terminal setups
Common files:
~/.bash_profile~/.bash_login~/.profile
Interactive non-login shell
Typical example:
- opening a new terminal window inside a graphical desktop
Common file:
~/.bashrc
That is why many users put reusable shell customizations in ~/.bashrc
and then make sure the login file loads it.
Environment Variables
Variables hold values the shell and programs can use.
Show variables
env | head
set | head
Set a variable in the current shell
EDITOR=nano
Export it to child processes
export EDITOR
Remove it
unset EDITOR
Important idea:
- variable only = current shell
- exported variable = child processes can see it too
PATH
PATH tells the shell where to search for commands.
Show it
echo "$PATH"
Extend it safely for the current shell
PATH="$HOME/bin:$PATH"
export PATH
Common beginner rule:
- add directories carefully
- keep standard directories in the value
- do not accidentally replace the whole old
PATHunless you mean to
Aliases
Aliases make short command shortcuts.
Example:
alias ll='ls -la'
Show aliases:
alias
Remove one:
unalias ll
Use aliases for:
- short convenience commands
- safer default flags
But remember:
- aliases are simple text substitutions
- they are not the same thing as full shell functions
Shell Functions
Functions are more powerful than aliases.
Example:
mkcd() {
mkdir -p "$1" && cd "$1"
}
Why functions matter:
- they can accept arguments
- they can run several commands
- they are good for repeated shell workflows
source and .
Sometimes you change a startup file and want the current shell to read it again.
Example:
source ~/.bashrc
. ~/.bashrc
These two forms mean the same thing in Bash.
/etc/skel/
This directory is the template for new user home directories.
Simple idea:
- files placed in
/etc/skel/are copied when a new user account is created - this is useful for default shell config files such as
.bashrc
That makes /etc/skel/ a very practical admin tool.
A Safe Customization Workflow
When changing a shell environment:
- decide whether the setting is global or per-user
- choose the correct startup file
- make a small change
- reload the file with
sourceor open a new shell - verify the result with
echo,env,type, oralias
Practice Step by Step
1) Add a temporary variable
- Run:
MYEDITOR=nano - Check it:
echo "$MYEDITOR" - Export it:
export MYEDITOR - Confirm it appears in:
env | grep MYEDITOR
2) Add a simple alias
- Run:
alias ll='ls -la' - Test it:
ll - Show all aliases:
alias
3) Reload `.bashrc` without logging out
- Edit
~/.bashrc. - Add a simple alias or variable.
- Reload it:
source ~/.bashrc - Test the new setting in the current shell.
Cheat Sheet
/etc/profile= common global login-shell config/etc/bash.bashrc= common global Bash interactive config on many systems~/.bash_profile,~/.profile= per-user login shell files~/.bashrc= per-user interactive Bash configexport= pass a variable to child processesunset= remove a variablePATH= command search pathalias= simple shell shortcutfunction= reusable command block with argumentssourceor.= load a shell file into the current shell/etc/skel/= template files for new user accounts
Test Your Knowledge
Complete the quiz to assess your understanding of this course's concepts.
