Keentune
Bash, oriented
10 chapters
·
about 17 min read
·
free
Bash is less a programming language than a text-rewriting machine that ends each line by running a program: it splits your line into words, rewrites some of them, and hands the result to a command. Nearly every shell bug called weird is that rewriting doing exactly what it was told, on input the author never pictured — a filename with a space, an empty variable, a pattern that matched nothing. Learn the rewriting order and where quoting stops it, and the language stops surprising you. Every behaviour below was executed rather than recalled, and where bash and a strict standard shell disagree, this guide says so.
Each chapter opens with the short version. Tap one to read the detail.
How a script starts, and why it behaves differently there
~2 min
A script runs in a fresh, non-interactive shell that reads none of your interactive startup files. That fact explains most "works in my terminal, fails from cron" reports. Running a script forks a child; source runs it inside the shell you are already in.
Quoting, and the one bug that outnumbers all the others
~2 min
An unquoted $var is not "the value". It is the value chopped into words at spaces, then each word matched against filenames. "$var" is always exactly one word. This habit alone removes more shell bugs than everything else in this guide put together.
The expansion pipeline: parameters, splitting and filename patterns
~3 min
Expansions run in a fixed order: braces, tilde, parameters and substitutions, then word splitting, then filename matching, then quote removal. Only those middle steps change how many words you have, and the order explains failures that look like syntax errors.
Variables, exports and arrays
~2 min
x=1 takes no spaces around the equals sign. A variable stays invisible to child processes until exported, and a child only ever receives a copy. An array is not a string: bare $a means element zero, and only "${a[@]}" yields one word per element.
Wiring: pipes, file descriptors and here-documents
~3 min
A pipeline reports only its last stage's status, so a command that dies mid-pipe looks like success. Redirections are pointer copies applied left to right, and they happen before the command runs — which is why their order matters so much.
Three different things: [ ], [[ ]] and (( ))
~2 min
[ is an ordinary command, so every space separates arguments and an unquoted empty variable becomes a syntax error. [[ ]] is shell syntax and never splits its operands. (( )) is integer arithmetic whose exit status is the inverse of the value.
Loops, functions, and where your state lives
~3 min
A subshell can run your code and then discard everything it changed. Pipelines, ( … ) and $( … ) all create one; { …; } and a shell function do not. Knowing which you are inside explains a counter that stays at zero and a local that hides a failure.
Exit status, set -euo pipefail, and what it does not catch
~2 min
A status of zero means success. Error-exit mode stops on a failing command, but never on one being tested — inside if, while, &&, || or after ! — and testing a function suspends it for that whole function body. Cleanup belongs in an exit trap.
The builtins that carry real scripts
~2 min
read -r and printf are the two you cannot work without: without -r a backslash is eaten, and echo's handling of options and escapes differs between shells on one machine. eval re-parses its argument, which is exactly why untrusted text must never reach it.
bash versus a POSIX sh
~2 min
#!/bin/sh does not promise bash. Under a strict standard shell, [[, arrays, here-strings and process substitution are syntax errors, source is not found, and [ a == b ] fails. Testing with your own sh proves nothing when that sh is bash under another name.
See the full Bash & Shell curriculum
Written by Keentune. We are not affiliated with or endorsed by the organizations whose documentation informs this guide, and any linked sources belong to their respective owners.
All exam, test, and product names and trademarks are the property of their respective owners and are used here for identification and reference only. Keentune is independent study practice — not affiliated with, authorized, or endorsed by any of these organizations.
© 2026 SportaApp LLC