Intro to Shell Scripting

Typing five commands in sequence every single day is tedious. A shell script bundles multiple commands into one file so you can run them all just by typing the filename. It's the backbone of automation for Linux engineers — and the syntax is surprisingly simple.

So what exactly is a shell script?

A shell script is a text file containing commands that a shell (like Bash) can interpret and execute. By convention the filename ends in .sh, and the contents are just the same commands you'd type in the terminal, lined up one after another. Add execute permission and it becomes a small program you launch by name.

For example, instead of manually creating a Python virtual environment, installing libraries, and running your script every time, you can write a single setup.sh file and be done with one command. Linux engineers constantly use shell scripts to automate repetitive and verification tasks.

Basic structure of a shell script

Practical example: daily automatic backup of a homework folder 10 lines to finish. Learn variables, conditionals, and file ops from a real example #!/bin/bash # Declare: run this with Bash # Back up the homework folder with a date stamp SRC= "$HOME/Documents/homework" # Source (your home folder) DST= "/mnt/usb/backup/$(date +%Y%m%d)" # Destination: dated folder if [ ! -d "$DST" ]; then # If the folder doesn't exist mkdir -p "$DST" # Create it fi cp -r "$SRC"/* "$DST/" # Copy everything inside echo "Backup done: $DST" $ ./backup.sh → "Backup done: /mnt/usb/backup/20260504"
Fig 1: A practical backup tool in 10 lines. Run by filename, and schedulable with cron for daily auto-execution.

The first line #!/bin/bash is called a "shebang" — it tells the system "run this file with Bash." After that, just write regular commands from top to bottom. Add execute permission with chmod +x hello.sh, then run it with ./hello.sh.

Variables and conditionals

Shell scripts support variables and if statements. Write name="Alex" to assign "Alex" to the variable name, then display it with echo "$name". Conditionals look like if [ "$1" = "hello" ]; then echo "hi"; fi — you can build logic like "warn if there are more than 10 files." It's not as complex as a full programming language, and you can pick up the basics in half a day.

What shell scripts can do

Time saved by scripting daily tasks Manual work × days adds up fast. The more repetitions, the bigger the gain. A. Rename 100 files (once a month) By hand 15 min × 12 months = 3 hrs/year Script 3 sec × 12 = 36 sec/year B. Log aggregation and report (every day) By hand 10 min × 365 days = 60 hrs/year Script cron auto-runs = 0 sec (unattended) C. Project environment setup (per new project) By hand 30 min + trying to remember the steps Script ./setup.sh = done in 1 minute
Fig 2: 10 min/day → 0 accumulates to 60 hrs saved per year. Learning this as a teen pays off enormously.

Recommended approach for teens

Tasks like "copy the contents of my homework folder to another drive every day," "auto-open VS Code and the browser when I boot up," or "move only 2026 photos to a separate folder" — scripting just one daily repetitive task lets you feel the power immediately. When a school assignment says "rename 100 images," five lines of script finishes it.

For your first script, prepare a practice folder that's safe to break, and start by just printing what would happen using echo. Don't run deletions or moves right away — display the target files on screen first, verify they're correct, then switch to the real operation. That's the safe way to work.

Once you're comfortable, look into set -e (stop on error), set -u (catch unset variables), and tee (write output to a log). These boost real-world usefulness. Because shell scripts are short and powerful, targeting the wrong folder can have big consequences — build them carefully, step by step.

Pitfalls to watch out for

Shell scripting cautions
  • Scripts containing rm require special care. If a variable is empty when the script runs, you could end up with something like rm -rf /* — a disaster.
  • Spaces are strict. name = "Alex" is an error; name="Alex" is correct.
  • Never run scripts copied from the internet with execute permission (e.g., curl | bash) without reading them first.

How will this help your future?

Shell scripting is foundational for infrastructure engineers, SREs, and DevOps practitioners. Server configuration automation, deployment pipelines, and log monitoring are all powered by shell scripts, Python, and tools like Ansible. Teens who have "written their own small scripts for daily use" develop a natural feel for using commands as tools.

Things you can do today

Get started in 3 steps
  1. Create a file with nano hello.sh, write #!/bin/bash and echo "Hello!" inside it.
  2. Add execute permission with chmod +x hello.sh, then run it with ./hello.sh.
  3. Bundle the 3 commands you type every day into a script and run it.

Summary

A shell script is a small program — multiple commands bundled into one file. Start with #!/bin/bash on line one, then write regular commands below. Variables and if statements are available too, so you can grasp the basics with a short practice session. Automate even one repetitive task and your efficiency and accuracy will improve right away.