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
#!/bin/bash
# Simple greeting script
NAME="Linux Learner"
echo "Hello, $NAME!"
echo "Today is $(date)"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.