Chapter 50: Scripting

Scripting — that is, Bash Scripting.

Imagine this:

  • Typing one command → like asking your friend to pass you one glass of water
  • Writing a script → like writing a small note: “Hey friend, please do these 10 things every morning: boil water, make chai, add sugar, pour in cup, bring it to my table, clean the stove, put the cup in sink, wipe table, close gas, and say ‘chai ready boss’.”

You give that note once → your friend does all 10 steps automatically every time you say “run the note”.

That’s exactly what Bash scripting is:

Writing many commands in a normal text file → giving it a name → telling Bash “please run everything written in this file one by one automatically”.

What is a Bash Script? (Super Simple Definition)

A Bash script is just a plain text file that contains:

  1. A special first line called shebang → tells the computer “use Bash to run this file”
  2. A list of Bash commands (the same ones you type in terminal)
  3. Comments (lines starting with #) so you remember why you wrote what

And once you make it executable (chmod +x), you can run the whole thing with one short command — like magic!

Why Learn Scripting in 2026? (Real Reasons from Hyderabad Life)

  • Automate boring/repetitive tasks (backup files every night, rename 500 photos, install software daily)
  • Deploy websites/servers faster (git pull + restart nginx + clear cache in one click)
  • Make your own tools (a personal “chai reminder” script, file organizer, system health checker)
  • Work on cloud servers / DevOps / automation (AWS, GitHub Actions, Docker, CI/CD all use Bash scripts)
  • Look super professional when you say “I wrote a script to do this”

Step-by-Step – Your First Real Script (Let’s Do It Together!)

Step 1: Create the File

Bash

Step 2: Write This (Copy Exactly – First Line is Magic!)

Bash

Step 3: Save & Exit

Nano: Ctrl+O → Enter → Ctrl+X

Step 4: Make It Executable (Super Important!)

Bash

Without this step → you get “Permission denied” when you try to run it.

Step 5: Run Your Script!

Two ways (both work):

Bash

You should see beautiful output like:

text

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

What Makes It a Script? (Key Parts Explained)

  1. Shebang line (must be first line, no space before #!)
Bash

Tells system: “Please use Bash interpreter to run this file”

  1. Comments (#)
Bash

Ignored by computer — but super important for future-you!

  1. Commands — same as terminal
Bash
  1. Special tricks inside scripts
Bash

Next Level – Make It Ask Your Name (Interactive Script)

Edit hello.sh again (nano hello.sh) and replace content with this:

Bash

Run it again:

Bash

Now it talks to you — this is interactive scripting!

Summary Table – Scripting Basics at a Glance

Part What it is Example / Rule
File name Usually ends with .sh hello.sh, backup.sh, deploy.sh
First line Shebang #!/bin/bash
Make executable chmod +x filename.sh Required to run with ./filename
Run it ./filename.sh or bash filename.sh ./ is current directory
Comments Lines starting with # # This is ignored
Variables name=”value” then echo “$name” Always quote “$var”
Run command in echo echo “Today: $(date)” $( ) = command substitution
Input from user read variable_name Waits for you to type

Your 7-Day Scripting Challenge (Start Today!)

Day 1 → Write & run the first hello.sh above Day 2 → Add read for name & age (like second example) Day 3 → Make a script that creates backup of ~/Documents (cp -r or tar) Day 4 → Add if-else: check if folder exists (test -d) Day 5 → Script that shows disk usage (df -h) + memory (free -h) Day 6 → Colorful output (echo -e “\e[32mSuccess!\e[0m”) Day 7 → Put it in ~/bin/ so you can run from anywhere

Got the big idea now? Scripting = turning many manual commands into one automatic superpower tool.

Any part confusing? Want next: “Teacher, explain variables in detail” or “if-else conditions” or “loops (for/while)” or “how to pass arguments to script” or “make script run every day automatically (cron)”?

Just say — teacher is ready in Hyderabad! Keep writing small scripts every day — soon you’ll feel like a Bash wizard! 🐧✨📜 😄

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *