Module 08 of 12

Bash Scripting Fundamentals

Lessons

About This Module

So far you've been typing commands one at a time. A Bash script is simply those same commands saved in a file so you can run them again with a single word. Add variables and a few decisions, and that file becomes a small program that can back up folders, set up a new machine, or check a server, all without you typing every step.

This module starts with your first script: writing it, adding the #!/bin/bash shebang line, making it executable with chmod +x, and running it. Next comes quoting, the difference between single and double quotes and why it decides whether $VARIABLE is expanded. Then exit codes: how every command reports success or failure, and how to read that with $?. The module finishes with conditionals, using if, elif, else, [ ], [[ ]] and case so your scripts can make decisions.

Write each example script yourself as you watch the lessons in order, then continue on to Loops, Functions & Arrays.

Lessons

4 videos
01

Write Your First Bash Program

The first step in Bash scripting: creating a simple script that prints "Hello world" to the console, then making it executable and running it from the terminal.

02

Single vs. Double Quotes in Bash

Why quotes matter in Bash. Inside single quotes everything is taken literally, while double quotes still expand variables and special characters. Getting this wrong is behind many confusing script bugs.

03

Exit Codes

Part of Learn Linux TV's Bash scripting course. It explains how Bash sees success and failure, how to read a command's exit code, what the numbers mean, and how to use exit codes to make scripts more reliable.

04

Bash Conditionals: IF / THEN / ELIF / ELSE

A thorough tour of decisions in Bash: basic if/then syntax, single vs. double brackets, reading input into variables, comparing strings, elif for multiple cases, file tests, and the case statement.