Website review
This review may include AI-generated content and is not individually verified. Domain, certificate and other facts come from the observed data on this page.
What is The Shell Scripting Tutorial?
The Shell Scripting Tutorial is a free, text-based course and reference for learning Bourne-compatible shell scripting on Unix and Linux. It teaches scripting by example alongside the underlying theory, covering the basics—first scripts, variables, wildcards, escape characters, loops, tests, case statements, external programs, and functions—plus hints, a quick reference, and exercises. It was written by Steve Parker, a senior DevOps engineer, and is designed both as a basis for one-on-one or group tutorials and as a reference to return to later.
Who it suits
- Beginners with some Unix exposure. The tutorial states it assumes some prior experience, so it is not a first introduction to the command line.
- Learners who want portability. It deliberately restricts itself to Bourne-compatible scripting, giving a baseline that works across many Unix and Linux environments rather than tying you to Bash-only features.
- Tutors and study groups. The exercise-based structure supports guided sessions.
Trade-offs to weigh
The Bourne-first focus is the main trade-off: you get scripts that travel well, but Bash-specific conveniences are treated as extras in a separate examples section rather than the core path. If your daily work is Bash on Linux, expect to supplement the fundamentals with those examples.
Next step
Open the "A First Script" page and work through it in a terminal as you read, then attempt the exercises before moving on. Readers who prefer an offline copy can buy the tutorial as a PDF; the author also wrote Shell Scripting: Expert Recipes for Linux and Bash. For a Bash-oriented alternative once the basics are solid, the GNU Bash manual at GNU Project is the authoritative reference.
How do I write my first Bourne shell script step by step?
Start with a single script that prints text, then add one new shell feature at a time. The Shell Scripting Tutorial is built for exactly this: it teaches Bourne-compatible scripting by example alongside the theory, and it explicitly assumes some prior experience rather than starting from zero.
A practical first-script path
- Create the file. Open a terminal and make a file such as
hello.shin your working directory. Use.shso the extension signals it is a shell script. - Add the shebang line. The first line should be
#!/bin/shto run it with a Bourne-compatible shell. This matters because the tutorial deliberately stays within Bourne-compatible features so scripts work across Unix and Linux systems, even though Bash is the most common modern shell. - Write one command. Put
echo "Hello from my first script"on the next line. Keep it to a single statement so you can see cause and effect. - Make it executable. Run
chmod +x hello.shso the system will treat it as a program. - Run it. Execute
./hello.shfrom the directory containing the file. If you see the greeting, the mechanics work. - Add variables. Introduce a variable such as
NAME="world"and use it in the echo line. The tutorial's sequence covers variables in several parts, which reflects how much nuance exists once you move past the basics. - Introduce control flow. Add an
iftest, then afororwhileloop, then acasestatement. These are separate chapters in the tutorial, and working through them in order prevents the common mistake of copying loops before understanding tests. - Factor out repetition with functions. Once a script has two or three repeated blocks, wrap them in a function. The tutorial treats functions as their own topic for good reason.
- Use the quick reference and exercises. The site includes a quick reference, an interactive shell section, and exercises. The exercises are the part most learners skip; doing them is what converts reading into recall.
Who this suits
The material is written as a basis for one-on-one or group tutorials and as a reference for later use, by an author with decades of Unix, Linux, and automation experience. That makes it a good fit for someone who already knows basic command-line navigation and wants a structured path, or for a team running a study group. A complete beginner with no terminal experience will need to learn basic commands first; the tutorial's stated assumption of prior experience means it will not walk through what cd or ls do.
A concrete scenario
Suppose you maintain a small Linux server and want a script that checks disk usage and emails you when a partition passes 90 percent. Start with the hello script above, then replace the echo with a df call, add an if test on the percentage, and wrap the whole thing in a function so you can call it for several mount points. Each step maps to one chapter of the tutorial, so you can build the script incrementally instead of writing it all at once.
Decision criterion
If you want a single linear course with exercises and a reference you can return to, work through this tutorial front to back. If you prefer video walkthroughs or a broader Linux administration curriculum, use this as your scripting reference and pair it with a general Linux course. For readers who want a book-length treatment, the same author's Shell Scripting: Expert Recipes extends beyond the tutorial's Bourne-only scope into Bash-specific features.
How do shell script variables, wildcards and escape characters work in practice?
Shell scripts handle variables, wildcards and escape characters in three distinct layers, and mixing them up causes most of the bugs beginners hit. Variables are plain name/value pairs you assign and expand; wildcards are expanded by the shell into matching filenames before your command runs; escape characters (and quoting) control when that expansion happens at all.
Variables
Assign without spaces around =, then expand with $name or ${name}. Braces matter when text follows the name, as in ${file}.bak, otherwise the shell reads $file.bak as a variable called file.bak. The tutorial treats variables across three separate chapters (Parts 1–3), which reflects how much behaviour sits behind a simple name=value line: quoting on assignment, defaults, and the difference between a variable you set and one you export to child processes. As a practical rule, quote expansions ("$var") unless you deliberately want word-splitting or wildcard expansion to happen on the value.
Wildcards
Patterns like *, ? and [abc] are matched against filenames by the shell itself, not by the program you call. So rm *.txt is really the shell building a list of matching files and passing them as arguments. Consequences worth knowing: a pattern that matches nothing is usually passed through literally (a classic source of "file not found" surprises), and filenames containing spaces break unquoted loops. The tutorial's Wildcards chapter sits early, before Loops, which is the right order — you need to understand expansion before writing for f in *.
Escape characters and quoting
Backslash escapes the next character's special meaning; single quotes protect everything inside; double quotes protect most things but still allow $ expansion. These are the tools for turning off the wildcard and word-splitting behaviour described above. The Escape Characters chapter follows Wildcards for exactly this reason: first learn what the shell does, then learn how to stop it.
How the pieces interact
| Construct | Expanded by shell? | Typical use |
|---|---|---|
$var unquoted |
Yes, plus word-splitting and wildcarding of the value | Rarely what you want |
"$var" |
Value only, no splitting or wildcarding | Safe default |
* unquoted |
Yes, to matching filenames | Bulk file operations |
"*" or \* |
No, literal asterisk | Passing a pattern to grep, find, etc. |
'$var' |
No | Literal text containing $ |
A concrete scenario: a backup script that loops over files. for f in $DIR/* breaks if DIR contains spaces or is empty; for f in "$DIR"/* keeps the directory intact while still letting the shell list files. Then cp "$f" "$f.bak" needs braces — "${f}.bak" — to avoid the shell hunting for a variable named f.bak.
Next step
Work through the tutorial's chapters in page order — Variables (Part 1), Wildcards, Escape Characters, Loops — writing and running each example rather than reading it, since expansion behaviour is far easier to see than to remember. The site also publishes a PDF version of the tutorial for offline reference, and its author, Steve Parker, has written Shell Scripting: Expert Recipes for readers who want to go past Bourne-compatible basics into Bash-specific features. If you prefer a different teaching style, GNU documents Bash itself, and The Linux Documentation Project hosts longer-form guides; the tutorial here is best treated as a structured course with exercises, not a complete language reference.
How can I use loops, test conditions and case statements to automate a Linux task?
Use loops to repeat work over a list of items, test/[ ] conditions to decide whether each step should run, and case to branch on a small set of known values. Together they turn a manual sequence of commands into one script that checks its own preconditions and handles variants without you retyping commands.
A concrete pattern
Suppose you need to clean up log files for several services and behave differently per service. A Bourne-compatible script can combine all three constructs:
for svc in web api db; do
dir="/var/log/$svc"
if [ -d "$dir" ]; then
case "$svc" in
web|api) keep=7 ;;
db) keep=30 ;;
*) keep=14 ;;
esac
find "$dir" -name '*.log' -mtime +"$keep" -delete
else
echo "Skipping $svc: $dir not found" >&2
fi
done
Here the loop supplies each service name, the if guards against a missing directory, and case encodes a per-service retention policy in one readable block. The same skeleton works for rotating files, restarting services, or syncing directories.
Choosing between if and case
| Situation | Better choice | Why |
|---|---|---|
| Yes/no check (file exists, variable empty, exit code zero) | if [ ... ] |
One condition, one branch |
| Two or three fixed alternatives | if/elif |
Simple and explicit |
Many fixed string values, or pattern matching (*.conf) |
case |
Flatter, easier to extend |
| Testing numeric ranges or comparing values | if with -eq, -lt, etc. |
case matches patterns, not ranges |
Practical advice
- Quote variables (
"$dir") inside tests so empty or space-containing values don't break the condition. - Use
casewhen the set of valid inputs is closed — it doubles as lightweight input validation, with a*)branch to reject anything unexpected. - Prefer
forover a list you control; usewhile readwhen looping over command output line by line. - Test destructive scripts on a copy or with
echoin place of the real command first.
The tutorial at The Shell Scripting Tutorial is organized around exactly this progression — separate chapters on loops, test, and case — and is written as a basis for tutorials and exercises as well as later reference, which suits someone learning the constructs in order rather than looking up syntax piecemeal. Its stated scope is Bourne-compatible scripting, so the patterns above should carry across most Unix and Linux environments; Bash-specific extras are treated separately in its examples section.
Is this tutorial suitable for beginners, and what prior Unix experience do I need?
Yes, but with a caveat: it is written for people who already have some Unix familiarity. The tutorial's own audience section says it "assumes some prior experience," and its purpose is to teach shell script programming on top of that. So it suits a beginner to scripting more than a complete beginner to Unix.
Who gets the most from it
- Newcomers to scripting with basic Unix exposure. If you can move around directories, edit a file and run commands in a terminal, you can follow the sequence from "A First Script" through variables, wildcards, loops,
testandcasewithout getting lost. - People learning in a structured way. The author says it was written as a basis for one-on-one or group tutorials and exercises, and as a reference afterwards, so it works for self-study or a study group.
- Readers who want portability. The material deliberately stays within Bourne-compatible scripting, giving a baseline that works across many Unix and Linux environments; Bash-specific extras appear in a separate examples section.
Who should prepare first
Someone with no command-line experience at all will struggle, because the tutorial builds on shell commands rather than teaching them. A practical test: open a terminal, create a directory, move into it, create a text file and run a command against it. If any step needs looking up, spend a few hours on basic Unix commands first, then return.
A useful next step
Start with the "A First Script" page and type each example yourself rather than reading it. If the first script runs and you understand each line, continue in order; if not, the gap is Unix basics, not scripting. For hands-on practice, the site's exercises and "Tips and Examples" sections are the natural follow-up, and the quick reference is handy once you are writing your own scripts.
For a second perspective on the same fundamentals, LinuxCommand.org is a long-running, beginner-oriented companion.
How do I get the latest version or PDF of this tutorial, and does it cost anything?
The latest version is always at the official site, The Shell Scripting Tutorial; version and last-updated information appears at the top-right of the page. A PDF version is sold for $7, so the online tutorial is the free route and the PDF is the paid one.
What to expect
- Online: free to read, organized as a sequence of lessons (first script, variables, wildcards, loops, functions, exercises) plus a quick reference.
- PDF: the same tutorial in a portable, offline format, purchased rather than freely downloaded.
Choosing between them
Read a few chapters online first. If you'll work away from a browser, want to annotate, or prefer a single file for group exercises—the stated purpose includes one-on-one and group tutorials—the PDF is the practical option. If you just need a reference while at a terminal, the free site is enough.
A useful next step
Open the site, note the version number at the top right, and begin with "A First Script" before moving to variables and loops. Keep the quick reference page open in a second tab as you practice.
User reviews (0)