Bash Tutorial

Bash — like a real teacher sitting next to you with a cup of chai, explaining everything step-by-step in very simple English with lots of examples.

Imagine your computer (especially Linux, macOS, or Windows with WSL/WSL2 or Git Bash) has two ways to talk to it:

  1. Clicking things (mouse + icons + windows) → this is called GUI (Graphical User Interface)
  2. Typing commands → this is called CLI (Command Line Interface) or Terminal

Bash is the most popular teacher/language that understands the commands you type in the terminal.

What does “Bash” actually stand for?

Bourne Again SHell (It’s a pun — improved version of the old “Bourne Shell” which was called sh)

So Bash = modern, powerful version of the old Unix command-line language.

Two Main Things Bash Does

  1. Interactive mode → You type one command → Bash runs it immediately (what most people do every day)
  2. Script mode → You write many commands in a file → Bash reads and runs all of them one by one automatically (this is called Bash scripting)

Most people say “Bash Tutorial” when they actually mean Bash Scripting Tutorial — how to write small programs (scripts) using Bash.

Let’s learn both parts properly!

Part 1: Using Bash Interactively (Daily Commands)

Open your terminal (on Ubuntu → Ctrl + Alt + T, on macOS → Terminal app)

Try these one by one:

Bash
Bash
Bash
Bash
Bash
Bash
Bash
Bash
Bash

These are the baby steps — Bash is just listening and running these small commands.

Part 2: Bash Scripting — Writing Mini Programs

Now the fun part begins!

A Bash script is just a normal text file that contains many commands — and you can run the whole file with one command.

Let’s create our first script.

Step 1: Create file

Bash

(or use any editor: gedit hello.sh, code hello.sh, vim hello.sh)

Step 2: Write this (very important — copy exactly)

Bash

Step 3: Save and exit (Nano: Ctrl+O → Enter → Ctrl+X)

Step 4: Give permission to run it (very important!)

Bash

Step 5: Run it!

Bash

You should see something like:

text

Congratulations! You just wrote and ran your first Bash script! 🎉

Very Important Concepts (Explained like to a friend)

  1. Shebang line must be first#!/bin/bash → tells computer: “Please use Bash to run this file”
  2. echo → prints message on screen
  3. $( ) → runs command and puts result inside

Example:

Bash

Variables (super useful)

Bash

Run it → output:

text

Taking Input from User (read command)

Bash

If-else condition (decision making)

Bash

For Loop (repeat something)

Bash

Better version (1 to 10):

Bash

While Loop (repeat until something)

Bash

Practical Real-life Script Example

Backup your important folder automatically:

Bash

Run daily → never lose files!

Quick Summary Table (most used things)

What you want to do Command/Example
Print something echo “Hello”
Store value name=”Sara”
Use variable echo $name or echo “$name”
Get input read city
Compare numbers [ $a -gt $b ]
Compare strings [ “$str” == “yes” ]
Run command and use result today=$(date)
If condition if [ condition ]; then … fi
Loop 1 to 10 for i in {1..10}; do … done

Want to go deeper? Tell me which topic you want next:

  • Functions in Bash
  • Arguments to scripts ($1, $2…)
  • Case statement
  • Working with files (find, grep, sed, awk)
  • Error handling
  • Cron jobs (run script automatically every day)

Just say — “explain Bash functions with examples” or anything!

Happy Bash learning! 🐧 Keep practicing — typing is the only way to become fast. 😊