Bash quick reference

Runs in Zerethon IDE · Bash 5.2 Official Bash documentation ↗

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, echo and printf, 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

    if with [[ ]] and (( )), case patterns, for over words, a range or a C-style counter, and while.

  • Functions and exit status

    Define functions, read arguments with $1 and "$@", return a status, output a value, and stop on errors with set -euo pipefail.

Data

  • Arrays and associative arrays

    Indexed arrays, "${arr[@]}", sorting through sort, and key/value maps with declare -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 token and Read-only file system mean and how to fix them.

  • Official documentation

    Where to read more: the GNU Bash Reference Manual and its sections on expansions, conditionals and builtins.

References