Bash · Foundations
Learn Bash
The syntax and the mental model. Short, runnable, no fluff.
Learn the Basics
01
Hello, World!
The tutorial discusses shell programming in general with focus on Bash (“Bourne Again Shell”) shell as the main shell interpreter.
02
Variables
Shell variables are created once they are assigned a value. A variable can contain a number, a character or a string of characters.
03
Passing Arguments to the Script
Arguments can be passed to the script when it is executed, by writing them as a space-delimited list following the script file name.
04
Arrays
An array can hold several values under one name. Array naming is the same as variables naming.
05
Basic Operators
Arithmetic Operators Simple arithmetics on variables can be done using the arithmetic expression: $((expression)) The basic operators are: a + b addition (a plus b) a - b substraction (a minus b) a b multiplication (a times b) a / b division (integer) (a divided by b) a % b modulo (the integer remainder of a divided by b) a b exponentiation (a to the power of b)
06
Basic String Operations
The shell allows some common string operations which can be very useful for script writing.
07
Decision Making
As in popular programming languages, the shell also supports logical decision making.
08
Loops
For each pass through the loop, arg takes on the value of each successive value in the list. Then the command(s) are executed.
09
Array-Comparison
Comparison of arrays Shell can handle arrays An array is a variable containing multiple values. Any variable may be used as an array.
10
Shell Functions
Like other programming languages, the shell may have functions. A function is a subroutine that implements a set of commands and operations.
11
Case Statements
Pattern matching on a string — cleaner than a chain of if/elif, and the backbone of every argument parser and dispatch table in shell.
Advanced Tutorials
01
Special Variables
In last tutorial about shell function, you use “$1” represent the first argument passed to functionA.
02
Bash trap command
It often comes the situations that you want to catch a special signal/interruption/user input in your script to prevent the unpredictables.
03
Input Parameter Parsing
Turning $@ into a usable set of options: manual loops, getopts, long flags, and the --dry-run habit that makes a script safe to run once.
04
File Testing
Often you will want to do some file tests on the file system you are running. In this case, shell will provide you with several useful commands to achieve it.
05
Pipelines
Pipelines, often called pipes, is a way to chain commands and connect output from one command to the input of the next.
06
Process Substitution
In the previous section we’ve seen how to chain output of one command to the next one.
07
Regular Expressions
Bash has a regex operator built in, and it is better than piping to grep for most jobs — once you know the two quoting rules that trip everyone up.
08
Special Commands: sed, awk, grep, sort
The four tools that do most of the work in most shell scripts, and the small subset of each that is worth memorising.
09
Redirection and Here Documents
Where output goes, where input comes from, and how to embed a block of text in a script without fighting quotes.
Get the Bash agent pack
A battle-tested AGENTS.md, the review checklist, and the failure-mode cheat sheet for Bash. One email, then occasional updates when the tooling shifts. No course pitch.
AGENTS.md now — no email needed.