What is a Shell?
If the Linux kernel is the engine of the car, the shell is your steering wheel and dashboard. It is the interface you use to control the system.
Shell as Command Interpreter
A shell is a program that:
- Reads commands you type
- Interprets them (variable expansion, globbing, pipeline assembly)
- Executes the appropriate programs
- Shows you the output
Think of it as a translator sitting between you and the operating system:
You type: ls -la /etc
Shell: "Find the program 'ls', pass it the arguments '-la' and '/etc', run it"
Kernel: executes ls, reads /etc directory
Shell: displays the result to your terminal
Without a shell, you would need to write programs in C and call kernel system calls directly every time you wanted to list files. The shell makes the kernel usable by humans.
Interactive vs Scripting Mode
Shells operate in two modes:
Interactive Mode
You type commands and see results immediately. This is what you use in the terminal day-to-day.
# Interactive — you type, shell responds immediately
$ echo "Hello"
Hello
$ pwd
/home/alice
Non-Interactive (Script) Mode
The shell reads commands from a file (a script) and executes them without waiting for your input.
#!/usr/bin/env bash
# This is a script file — myscript.sh
echo "Starting backup..."
cp -r /home/alice/docs /backup/docs
echo "Backup complete."
# Run it:
$ bash myscript.sh
Starting backup...
Backup complete.
The same shell program handles both modes. The difference is whether commands come from a human typing or from a file being read.
Shell Startup Files
When a shell starts, it reads configuration files to set up your environment. Which files it reads depends on the mode.
Login Shell (ssh login, terminal login)
Reads these files in order:
/etc/profile— system-wide settings (all users)~/.bash_profileOR~/.bash_loginOR~/.profile— first one found
Interactive Non-Login Shell (new terminal window in a GUI)
Reads:
/etc/bash.bashrc— system-wide~/.bashrc— your personal settings
Non-Interactive Shell (scripts)
Reads:
- Neither
.bashrcnor.bash_profileby default - Only the
BASH_ENVvariable file, if set (rarely used)
Practical rule of thumb:
- Put aliases and shell customisations in
~/.bashrc - Put environment variables that need to be available everywhere in
~/.bash_profile(and source.bashrcfrom it)
# ~/.bash_profile — common pattern
if [[ -f ~/.bashrc ]]; then
source ~/.bashrc
fi
Login Shell vs Non-Login Shell
| Scenario | Shell Type | Files Read |
|---|---|---|
ssh user@server |
Login shell | /etc/profile, ~/.bash_profile |
| Opening a new terminal window in Ubuntu desktop | Non-login interactive | ~/.bashrc |
Running bash script.sh |
Non-interactive | Nothing (by default) |
su - username (note the -) |
Login shell | Profile files |
su username (no -) |
Non-login interactive | .bashrc |
Checking and Changing Your Shell
# Check your current shell
echo $SHELL
/bin/bash
# Check which shell is actually running right now
echo $0
bash
# List all available shells on the system
cat /etc/shells
/bin/sh
/bin/bash
/usr/bin/bash
/bin/dash
/bin/zsh
/usr/bin/zsh
# Change your default login shell to zsh
chsh -s /bin/zsh
# (takes effect on next login)
Key Takeaways
- A shell is a command interpreter — it translates your commands into kernel calls
- Shells have two modes: interactive (you type) and non-interactive (scripts)
- Different startup files run depending on whether the shell is a login shell or not
~/.bashrcis for interactive customisation;~/.bash_profileis for login sessions$SHELLshows your default shell;$0shows what is running right now
| ← Back to Overview of Bash | Next → Bash vs sh vs zsh vs fish |