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
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
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
- Scripts containing
rmrequire special care. If a variable is empty when the script runs, you could end up with something likerm -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
- Create a file with
nano hello.sh, write#!/bin/bashandecho "Hello!"inside it. - Add execute permission with
chmod +x hello.sh, then run it with./hello.sh. - Bundle the 3 commands you type every day into a script and run it.
Summary
#!/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.