Bash vs. Shell vs. Terminal

Su Suriya Ravichandran Updated 06 Dec 2026
6 min read ·Lesson 4 of 205

The words shell, Bash, and terminal are often used as if they meant the same thing, but they describe three different parts of a command-line session. Keeping them apart makes it much easier to understand error messages, configuration files, and instructions you find online. In short, the terminal is the window, the shell is the program that interprets your commands, and Bash is one particular shell.

Understanding the Concept

A command-line session is built from layers:

You  →  Terminal  →  Shell (Bash)  →  Commands and programs  →  Kernel
  • The terminal displays text and sends your key presses onward.
  • The shell reads what you typed, interprets it, and starts programs.
  • Bash is the specific shell program that does the interpreting.

Each layer can be replaced independently. You can run Zsh inside a terminal that previously ran Bash, or you can run Bash inside a different terminal application. Nothing about the shell forces you to use a particular terminal, and nothing about the terminal forces you to use a particular shell.

The Terminal

A terminal, also called a terminal emulator, is a program that provides a text window. Its responsibilities are narrow:

  • Draw characters, colors, and the cursor on screen.
  • Capture keyboard input and send it to the program running inside.
  • Handle scrolling, copy and paste, tabs, and fonts.

The terminal does not understand commands. If you type ls and press Enter, the terminal simply forwards those characters. It is the shell that decides that ls is a program to start.

Examples of terminal programs include GNOME Terminal, Konsole, xterm, iTerm2, the macOS Terminal app, Windows Terminal, and the integrated terminal in many code editors.

Where the Name Comes From

Early computers were controlled through physical devices that had a keyboard and a printer or screen. These devices were called terminals because they sat at the end of a connection to a large computer. Today the physical device is gone, and software imitates it. That is why the modern program is called a terminal emulator, and why you will sometimes see it called a TTY, short for teletypewriter.

The Terminal Type

A terminal announces its capabilities to programs through the TERM environment variable:

echo "$TERM"

Sample output:

xterm-256color

On the machine used to test this lesson, the value was linux. Programs such as editors and pagers read this variable to learn which colors and control sequences the terminal supports.

Checking Whether a Terminal Is Attached

The tty command prints the name of the terminal device connected to the shell:

tty

Sample output in a terminal window:

/dev/pts/0

When a command runs without a terminal, for example inside an automated job, tty prints:

not a tty

This distinction matters because programs sometimes behave differently depending on whether a person is watching.

The Shell

A shell is the program that interprets commands. It runs inside the terminal, reads each line you type, and executes it. The shell is also a scripting language, so it can read commands from a file when no terminal is involved at all.

Because the shell does not draw anything itself, it does not need a screen. You can run a shell in a terminal, over a network connection, inside a container, or as a background process started by a scheduler.

The previous lesson, What Is a Shell?, describes what the shell does in detail. The key point for this lesson is that "shell" is a category of program. Bash, Zsh, Fish, Dash, and Ksh are all shells.

Bash

Bash is one specific shell, the Bourne Again Shell. It is a program stored on disk, usually at /bin/bash. If the shell is the category, Bash is one member of it, much like "web browser" is a category and Firefox is one browser.

You can confirm that the program in your terminal is Bash:

ps -p $$ -o comm=

Output:

bash

$$ is the process ID of the current shell, and ps prints the name of that process. If you were using Zsh, the output would be zsh.

Putting the Three Together

Open a terminal and type a command, and all three pieces take part:

  1. You press keys. The terminal captures them and sends them to the shell.
  2. Bash reads the line echo hello, recognizes echo as a built-in command, and runs it.
  3. Bash writes hello to its standard output, which is connected to the terminal.
  4. The terminal receives the characters and displays them.

The following table compares the three terms side by side:

TermWhat it isMain jobExamples
TerminalA window program (terminal emulator)Display text, capture keystrokesGNOME Terminal, iTerm2, Windows Terminal
ShellA command interpreterRead commands, start programs, run scriptsBash, Zsh, Fish, Dash
BashOne particular shellInterpret the Bash language/bin/bash

Shell Level and Nested Shells

Because a shell is just a program, you can start one shell from inside another. Bash keeps a counter called SHLVL that records how deep the nesting goes:

echo "outer=$SHLVL"
bash -c 'echo "inner=$SHLVL"'

Output:

outer=1
inner=2

The inner command starts a second Bash process, and that process increases the counter by one. When it ends, you return to the outer shell. This also shows that changes made in a nested shell do not carry over to the outer shell. For example:

bash -c 'exit 3'
echo "status=$?"

Output:

status=3

The inner shell ends with exit status 3, and the outer shell receives that number in $?. Nothing else from the inner shell survives.

Common Confusions

Several everyday phrases blur these terms. Reading them correctly clears up a lot of confusion.

"Open the Bash terminal"

This usually means "open a terminal window that runs Bash." The window is the terminal and the program running in it is Bash.

"Run it in the shell"

This means typing the command at a shell prompt, or running it in a script that a shell executes. It says nothing about which shell or which terminal.

"Command prompt," "PowerShell," and "CMD" on Windows

These are shells too, but they are not Bash. Windows Command Prompt and PowerShell have their own languages with different syntax. To use Bash on Windows, you start a Bash shell through WSL or a tool such as Git Bash, and run it inside a terminal such as Windows Terminal.

"SSH into the server"

When you connect to a remote machine with SSH, your local terminal displays the session, but the shell runs on the remote machine. You type in one place and the commands execute in another. This works precisely because the terminal and the shell are separate.

Why the Difference Matters in Practice

  • Configuration. Terminal settings, such as fonts and colors, live in the terminal application. Shell settings, such as aliases and the prompt, live in files like ~/.bashrc. Editing the wrong place has no effect.
  • Troubleshooting. A garbled display or broken colors is often a terminal issue. A "command not found" message is a shell issue.
  • Scripts. A script can be executed without any terminal, for example from a scheduler, so it must not assume a person is present.
  • Portability. Instructions for "the shell" might use Bash-only syntax. Knowing that Bash is one choice among several helps you spot instructions that will not work in another shell.

Seeing the Pieces on Your Own System

Three short commands show the layers on a real machine:

echo "$TERM"
ps -p $$ -o comm=
echo "$BASH_VERSION"

The first reports the terminal type, the second reports the shell program in use, and the third reports the Bash version if the shell is Bash. Together they answer the three questions: what kind of terminal, which shell, and which version.

0 Comments

Reviewed before they appear

No comments yet.

Bash
Introduction to Bash What Is a Shell? What Is Bash (Bourne Again Shell)? Bash vs. Shell vs. Terminal Bash vs. sh, Zsh, and Fish Where Bash Is Used: Linux, DevOps, and Automation Installing Bash on Linux Using Bash on macOS Using Bash on Windows with WSL Checking Your Bash Version Opening and Using a Terminal Running Your First Bash Command Understanding Command Syntax and Arguments Bash Built-in Commands vs. External Commands Working with pwd, ls, and cd Creating Files and Directories with touch and mkdir Copying, Moving, and Renaming Files Removing Files and Directories Safely Viewing Files with cat, less, head, and tail Searching for Files with find Searching Text with grep Understanding File Paths and Wildcards Using man Pages and Command Help Bash Script Structure Creating Your First Bash Script Understanding the Shebang (#!/usr/bin/env bash) Making a Script Executable with chmod Running a Bash Script in Different Ways Writing Comments in Bash Using echo and printf Reading User Input with read Displaying Helpful Messages in Scripts Using Semicolons and Newlines Bash Variables: Declaration and Usage Rules for Naming Bash Variables Environment Variables Local Variables vs. Environment Variables Exporting Variables with export Common Environment Variables: HOME, PATH, USER, and PWD Read-Only Variables with readonly Removing Variables with unset Command-Line Arguments: $0, $1, and More Special Parameters: $#, $?, $$, $!, $@, and $* Positional Parameters and shift Default Values with Parameter Expansion Single Quotes vs. Double Quotes Escaping Special Characters Command Substitution with $(...) Arithmetic Expansion with $((...)) Brace Expansion Tilde Expansion and Home Directories Filename Expansion and Globbing Understanding Word Splitting Parameter Expansion Basics Why Quoting Variables Matters Standard Input, Standard Output, and Standard Error Redirecting Output with > and >> Redirecting Input with < Redirecting Errors with 2> Combining Standard Output and Standard Error Using Pipes (|) to Connect Commands Using tee to Save and Display Output Here Documents with << Here Strings with <<< Command Lists with ;, &&, and || Conditional Statements with if, then, and fi Using elif and else Testing Conditions with test and [ ] Using [[ ]] for Bash Conditionals Comparing Strings in Bash Checking Whether Files Exist Checking File Types and Permissions Integer Comparisons in Bash Logical Operators: &&, ||, and ! Using case Statements Pattern Matching in case Common Conditional Statement Mistakes for Loops in Bash C-Style for Loops while Loops until Loops Looping Through Files and Directories Looping Through Command Output Safely break and continue Nested Loops select Loops for Simple Menus Avoiding Infinite Loops Defining and Calling Bash Functions Passing Arguments to Functions Returning Status Codes from Functions Understanding return vs. echo in Functions Local Variables in Functions Function Scope and Variable Visibility Organizing Scripts into Functions Sourcing Other Bash Files with source Reusable Bash Utility Functions Indexed Arrays in Bash Creating and Accessing Array Elements Adding and Removing Array Elements Looping Through Arrays Array Length and Indices Associative Arrays in Bash Iterating Over Associative Arrays Passing Arrays to Functions Common Array Pitfalls Processing Text with grep, sed, and awk Using cut, sort, uniq, and wc Finding and Replacing Text with sed Extracting Columns with awk Parsing CSV-Like Text from the Command Line Working with Filenames That Contain Spaces Safe File Handling with find -print0 and xargs -0 Temporary Files with mktemp Reading Files Line by Line Appending Logs to a File Understanding Exit Codes Checking Command Success with $? Using exit to End a Script Fail-Fast Scripts with set -e: Benefits and Caveats Using set -u and set -o pipefail Combining Strict Mode Options Safely Handling Errors with if Statements Traps with trap Cleaning Up Temporary Files on Exit Writing Useful Error Messages Debugging Scripts with bash -x Parsing Script Arguments Validating Required Arguments Handling Optional Arguments Parsing Options with getopts Building Help Messages with --help Setting Defaults for Optional Parameters Handling Unknown Options and Invalid Input Creating Interactive Menus in Bash Foreground and Background Processes Running Commands in the Background with & Managing Jobs with jobs, fg, and bg Waiting for Processes with wait Capturing Process IDs with $! and $$ Sending Signals with kill Handling Interrupts and Termination Signals Running Commands with timeout Basic Process Monitoring from Bash Aliases and Shell Functions: When to Use Each Customizing the Bash Prompt (PS1) Bash Startup Files: .bashrc, .bash_profile, and Profile Interactive vs. Non-Interactive Bash Shell Options with set shopt: Enabling Bash-Specific Options Directory Stack with pushd, popd, and dirs Process Substitution with <(...) and >(...) Advanced Parameter Expansion Pattern Matching and Extended Globbing Bash Script Security Fundamentals Avoiding Command Injection in Shell Scripts Quoting User Input Safely Why eval Is Risky and Safer Alternatives Handling Secrets and Credentials in Scripts Using Least Privilege in Automation Scripts Safe Use of rm and Destructive Commands Validating Paths and User-Supplied Filenames ShellCheck: Static Analysis for Bash Scripts Writing Readable and Maintainable Bash Automating Backups with Bash Creating Log Rotation and Cleanup Scripts Checking Disk Usage and Free Space Monitoring CPU, Memory, and System Load Checking Website Availability with curl Automating Updates on Ubuntu and Debian Scheduling Bash Scripts with cron Using Lock Files to Prevent Duplicate Runs Building a Simple Health-Check Script Sending Notifications from Bash Scripts Using Bash in Git Workflows Bash Scripts for Docker Automation Automating Docker Container Health Checks Using Bash in CI/CD Pipelines Environment Configuration for Deployment Scripts Automating SSH Tasks with Bash Deploying a Web Application with a Bash Script Using Bash to Process Application Logs Building Repeatable Development Setup Scripts Bash Debugging Techniques Using set -x and PS4 for Debug Traces Testing Bash Scripts with Bats Mocking Commands During Script Tests Testing Error Paths and Exit Codes Writing Portable Shell Scripts Bash-Specific Syntax vs. POSIX Shell Syntax Using ShellCheck in a Development Workflow Performance Tips for Bash Scripts Build an Interactive Calculator Build a File and Directory Organizer Build a Timestamped Backup Script Build a Log File Analyzer Build a Bulk File Renaming Tool Build a System Resource Monitoring Script Build a Website Uptime Checker Build a User Account Audit Report Build a Database Backup Automation Script Build a Docker Cleanup Helper Build a Server Health-Check and Alert Script Build a Deployment Automation Script Build a Menu-Driven Linux Administration Toolkit Build a Safe Automated Backup and Restore Workflow
Ask about this post
AI Ask about this post

Ask questions about Bash vs. Shell vs. Terminal and get answers drawn from it.

Signed-in readers only.