Bash quick reference
Bash 5.2 essentials: variables and quoting, arithmetic, conditions and loops, functions and exit status, arrays, string expansions, input, files, pipes and the standard tools — and how a script runs in Zerethon IDE.
Written for Bash 5.2. Examples that show an output were run in the Zerethon sandbox (Bash 5.2) on 2026-10-24.
Basics
-
Hello, World
The smallest Bash script,
echoandprintf, and why to quote variables. -
Variables and arithmetic
Assign without spaces, use
$((...))for integer arithmetic, capture output with$(...), and give defaults with${var:-default}. -
Conditions and loops
ifwith[[ ]]and(( )),casepatterns,forover words, a range or a C-style counter, andwhile. -
Functions and exit status
Define functions, read arguments with
$1and"$@", return a status, output a value, and stop on errors withset -euo pipefail.
Data
-
Arrays and associative arrays
Indexed arrays,
"${arr[@]}", sorting throughsort, and key/value maps withdeclare -A. -
Strings
Change case, cut, replace and trim text with parameter expansion, split on a delimiter, and match with
=~. -
Pipes and tools: grep, sed, awk, sort
Chain commands with
|, and the text tools available to scripts:grep,sed,awk,sort,uniq,cut,tr,wc.
Input and files
-
Reading input (stdin)
Read what you type in the IDE's Input tab with
read, one line or every line. -
Reading and writing files
Read project files line by line, redirect output with
>and>>, write here-documents, and keep temporary files under/tmp. -
Several files: source
Keep shared functions in another file and load them with
source.
In Zerethon IDE
-
Running Bash in Zerethon IDE
What Run does with your script, the time limit, input, tests, and what a run cannot do.
-
Common errors
What
command not found,unbound variable,unary operator expected,syntax error near unexpected tokenandRead-only file systemmean and how to fix them. -
Official documentation
Where to read more: the GNU Bash Reference Manual and its sections on expansions, conditionals and builtins.