Thuta Learning
IntermediateDevOps & Toolsbeginner

Shell Scripting Basics

Relax. We'll talk through this in plain words — no textbook voice.

What you'll walk away with

  • Understand Shell Scripting Basics without any of the intimidation
  • Get hands-on practice trying out the commands yourself in the terminal
  • See how these commands actually come in handy on a real server or project

Let's think about it this way for a second

A shell script is just a text file packed with a bunch of commands — the .sh extension is a common convention, but on Linux the extension itself has no effect on whether the file can execute (what matters is the execute permission, (x)). The very first line of the file needs a 'shebang' line, #!/bin/bash — this is the instruction that says 'run this script with bash.' You create a variable with NAME="value" and reference it with $NAME (no spaces allowed — writing NAME = value with spaces will throw an error). To write a comment, just prefix it with #.

Let's connect this to a real-world scenario

When you're backing up a server or setting up a project, instead of typing out 10 commands by hand every time, you write a backup.sh script once and then the whole process runs from a single ./backup.sh command — and it also cuts down on mistakes, since it always runs exactly the commands you wrote. Once you've written a script, you'll find yourself reaching for chmod +x (from the previous chapter) again and again.

Let's try it together in the terminal

bash
#!/bin/bash
# Simple greeting script
NAME="Linux Learner"
echo "Hello, $NAME!"
echo "Today is $(date)"
You should see
Running ./greet.sh prints 'Hello, Linux Learner!' along with today's date to the terminal.

5-minute try-it

Create a script called greet.sh — include a shebang line, a variable, and two echo lines. Run chmod +x on it and try it out.

A quick word of caution

If a script contains dangerous commands (rm, sudo), read through it carefully yourself before running it — once you run a script, every line inside it executes automatically.

Easy traps

  • Adding a space in a variable assignment like NAME = "value" and getting a 'command not found' error
  • Putting the shebang line (#!/bin/bash) somewhere among the comments instead of as the very first line of the file

Now try it yourself

Create a script called greet.sh — include a shebang line, a variable, and two echo lines. Run chmod +x on it and try it out.

You'll know it worked when: Running ./greet.sh prints 'Hello, Linux Learner!' along with today's date to the terminal.