Introduction to Bash

Bash stands for Bourne Again SHell. It is a command-line interpreter that reads commands typed by the user and tells the operating system what to do. Think of Bash as a translator between humans and the computer. Instead of clicking buttons, the user types instructions, and Bash executes them instantly.

Bash is the default shell on most Linux systems and macOS. It is also available on Windows through tools like Git Bash or Windows Subsystem for Linux (WSL).

What Is a Shell?

A shell is a program that sits between the user and the operating system. It takes commands from the user, passes them to the OS, and shows the result back on the screen.

┌──────────────────────────────────────────┐
│              USER (You)                  │
│         Types a command                  │
└───────────────────┬──────────────────────┘
                    │
                    ▼
┌──────────────────────────────────────────┐
│              SHELL (Bash)                │
│     Reads, interprets the command        │
└───────────────────┬──────────────────────┘
                    │
                    ▼
┌──────────────────────────────────────────┐
│         OPERATING SYSTEM (Linux)         │
│         Performs the actual task         │
└──────────────────────────────────────────┘

Why Learn Bash?

Bash is one of the most useful skills for anyone working with Linux or Mac systems. Here are the main reasons to learn it:

  • Automate repetitive tasks – Run hundreds of commands with a single script instead of doing them one by one.
  • Manage files and folders – Create, move, copy, delete files quickly from the command line.
  • Work faster – Experienced developers use Bash because it is much faster than clicking through menus.
  • Server management – Most web servers run Linux. Bash is the primary way to control them.
  • DevOps and CI/CD – Almost every automation pipeline uses shell scripts.

Bash vs Other Shells

There are several shells available. Bash is the most popular, but it helps to know the others exist.

ShellFull NameNotes
bashBourne Again ShellDefault on most Linux and macOS (older versions)
shBourne ShellOriginal Unix shell, very basic
zshZ ShellDefault on macOS (newer versions), advanced features
kshKorn ShellPopular in enterprise Unix environments
fishFriendly Interactive ShellUser-friendly, auto-suggestions

How to Check the Current Shell

Open the terminal and type the command below to see which shell is currently running:

echo $SHELL

Output:

/bin/bash

This output confirms that Bash is the active shell.

How to Check the Bash Version

bash --version

Output:

GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)

What Is a Bash Script?

A Bash script is a plain text file that contains a list of Bash commands. Instead of typing each command one by one, all commands sit inside a single file. When the file runs, Bash executes every command from top to bottom.

Think of a Bash script like a recipe. The recipe lists every step in order. The cook (Bash) follows each step until the dish (result) is ready.

┌──────────────────────────────────────┐
│          script.sh (Recipe)          │
│                                      │
│  Line 1: echo "Hello"                │
│  Line 2: echo "Welcome to Bash"      │
│  Line 3: date                        │
└──────────────────────────────────────┘
           │
           ▼ Bash runs each line
┌──────────────────────────────────────┐
│              OUTPUT                  │
│  Hello                               │
│  Welcome to Bash                     │
│  Sat Apr 18 10:00:00 UTC 2026        │
└──────────────────────────────────────┘

The Shebang Line

Every Bash script starts with a special first line called the shebang. It tells the operating system which interpreter to use when running the script.

#!/bin/bash

The #! symbol is called the shebang. The path /bin/bash tells the system to use Bash to run this file. Always include this line as the very first line of every Bash script.

First Bash Script – Hello World

Follow these steps to create and run the first Bash script:

Step 1: Create the file

nano hello.sh

Step 2: Write the script

#!/bin/bash
echo "Hello, World!"

Step 3: Save and exit

Press Ctrl + O to save, then Ctrl + X to exit the nano editor.

Step 4: Make the script executable

chmod +x hello.sh

Step 5: Run the script

./hello.sh

Output:

Hello, World!

What Does chmod +x Mean?

By default, a new file does not have permission to run as a program. The command chmod +x filename gives the file execute permission. Without this step, Bash will refuse to run the script.

┌─────────────────────────────────────────┐
│  Permission Flow                        │
│                                         │
│  New file → No execute permission       │
│  chmod +x → Execute permission added   │
│  ./script.sh → Script runs             │
└─────────────────────────────────────────┘

Comments in Bash

A comment is a line that Bash ignores completely. Comments exist only for humans reading the code. Use the # symbol to write a comment.

#!/bin/bash
# This script prints a welcome message
echo "Welcome to eStudy247 Bash Course"

# The line below shows today's date
date

Bash skips every line that starts with #. Comments help explain what the script does, making it easier for others (and future self) to understand the code.

Running Bash Commands Directly in the Terminal

Every Bash command works directly in the terminal without a script file. Open the terminal and type these commands one at a time:

echo "Hello from terminal"
date
whoami
pwd

Each command runs immediately and shows the result. This is called an interactive Bash session.

Key Takeaways

  • Bash is a shell — a bridge between the user and the operating system.
  • A Bash script is a text file with commands inside it.
  • Every script starts with #!/bin/bash on the first line.
  • Use chmod +x to make a script runnable.
  • Use # to write comments — Bash ignores these lines.

Leave a Comment