Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

Programming languages

Bash & the POSIX Shell

Bash and the POSIX shell from the first command to production scripts: expansion, quoting, tests, loops, pipes, functions, text tools and portability.

75 lessons to read 17 modules

75 lessons: 75 free with Pro answers.

Examples run with Bash 5.3.20, dash 0.5.13.5 and shellcheck 0.11.0.

Who it is for

Developers, DevOps learners and students who need to automate the command line.

What you will be able to do

  • Explain how Bash reads, expands and runs a command line, and quote every word correctly
  • Write scripts with variables, tests, loops, functions and arrays that pass ShellCheck
  • Redirect and pipe data between programs and process text with grep, sed, awk, find and jq
  • Make scripts robust with exit statuses, error handling, traps and debugging
  • Build command-line tools with options, help text and meaningful exit codes
  • Manage processes, jobs and signals, and set up a fast interactive shell
  • Write portable POSIX sh, spot GNU and BSD differences, and keep untrusted input safe
  • Test, format and speed up scripts, and choose when another tool fits better

Revise and practise

Modules and lessons

What the labels mean

Free lesson, Pro answers
the whole lesson is free; the model answers to its interview questions open with a pass
Pro
opens with a Pro, Premium or Ultimate pass

Minutes are reading time.

What a pass opens in this track

153 interview answers. The same pass opens every other track and every Pro tool.

  1. Module 1

    Start here: the shell, the terminal and your first script

    What a terminal and a shell are, which Bash you have, how commands, options and help work, moving around files, and writing and running a first script.

    1. Shells, terminals and which Bash you have Beginner Free lesson, Pro answers: 5 minutes
    2. Commands, options, arguments and help Beginner Free lesson, Pro answers: 5 minutes
    3. Files and directories from the command line Beginner Free lesson, Pro answers: 5 minutes
    4. Your first script: shebang, chmod and running it Beginner Free lesson, Pro answers: 5 minutes
  2. Module 2

    How Bash reads a command line

    The order in which Bash parses and expands a command line: quoting, word splitting, globbing, brace and tilde expansion, and printing with printf and echo.

    1. How Bash reads a line: tokens and expansions Beginner Free lesson, Pro answers: 5 minutes
    2. Quoting: single, double, backslash and $'...' Beginner Free lesson, Pro answers: 5 minutes
    3. Word splitting and IFS: why "$var" needs quotes Beginner Free lesson, Pro answers: 5 minutes
    4. Globbing: wildcards, dotfiles, extglob, globstar Beginner Free lesson, Pro answers: 5 minutes
    5. Brace and tilde expansion Beginner Free lesson, Pro answers: 5 minutes
    6. printf and echo: printing text reliably Beginner Free lesson, Pro answers: 5 minutes
  3. Module 3

    Variables, parameters and arithmetic

    Shell and environment variables, positional and special parameters, parameter expansion for defaults and strings, namerefs and integer arithmetic.

    1. Variables, export and the environment Beginner Free lesson, Pro answers: 5 minutes
    2. Positional and special parameters Beginner Free lesson, Pro answers: 5 minutes
    3. Defaults and required values: ${v:-x}, ${v:?} Beginner Free lesson, Pro answers: 5 minutes
    4. String operations with parameter expansion Beginner Free lesson, Pro answers: 5 minutes
    5. Indirection, namerefs and ${var@Q} transforms Intermediate Free lesson, Pro answers: 5 minutes
    6. Integer arithmetic: $(( )), (( )) and let Beginner Free lesson, Pro answers: 5 minutes
  4. Module 4

    Exit status, tests and branching

    Exit statuses and command lists, test and [ ], [[ ]] conditions, and branching with if, elif, else and case.

    1. Exit status, &&, || and command lists Beginner Free lesson, Pro answers: 5 minutes
    2. test and [ ]: file, string and number checks Beginner Free lesson, Pro answers: 5 minutes
    3. [[ ]]: patterns, regex and BASH_REMATCH Intermediate Free lesson, Pro answers: 5 minutes
    4. if, elif, else and case statements Beginner Free lesson, Pro answers: 5 minutes
  5. Module 5

    Loops

    for, while and until loops, break and continue, and reading files and command output line by line without losing data.

    1. for loops: lists, globs, ranges and C-style Beginner Free lesson, Pro answers: 10 minutes
    2. while, until, break, continue and select Beginner Free lesson, Pro answers: 10 minutes
    3. Reading files line by line with read Intermediate Free lesson, Pro answers: 10 minutes
  6. Module 6

    Redirection, pipes and substitution

    Redirecting standard input, output and error, pipelines and pipefail, here-documents, file descriptors with exec, and command and process substitution.

    1. Redirection: stdin, stdout, stderr, /dev/null Beginner Free lesson, Pro answers: 15 minutes
    2. Pipelines, PIPESTATUS and pipefail Intermediate Free lesson, Pro answers: 10 minutes
    3. Here-documents and here-strings Beginner Free lesson, Pro answers: 10 minutes
    4. File descriptors and exec redirections Advanced Free lesson, Pro answers: 10 minutes
    5. Command and process substitution Intermediate Free lesson, Pro answers: 10 minutes
  7. Module 7

    Functions and script structure

    Writing functions, returning values and statuses, local variables, sourcing libraries and laying out a script so it is easy to read and change.

    1. Functions: arguments, local and return status Beginner Free lesson, Pro answers: 10 minutes
    2. Returning values from functions Intermediate Free lesson, Pro answers: 15 minutes
    3. Script structure: main, source and libraries Intermediate Free lesson, Pro answers: 10 minutes
  8. Module 8

    Arrays and lists

    Indexed and associative arrays, and using arrays to build commands and lists safely without word-splitting bugs.

    1. Indexed arrays: create, slice and loop Intermediate Free lesson, Pro answers: 10 minutes
    2. Associative arrays: key-value maps Intermediate Free lesson, Pro answers: 10 minutes
    3. Lists done right: arrays, mapfile and read -a Intermediate Free lesson, Pro answers: 15 minutes
  9. Module 9

    Robust scripts: errors, traps and debugging

    set -e, set -u and pipefail with their limits, traps and cleanup, error-handling patterns, and debugging scripts with xtrace and other tools.

    1. set -e, set -u and pipefail: what they really do Intermediate Free lesson, Pro answers: 10 minutes
    2. Traps and cleanup: EXIT, ERR and signals Intermediate Free lesson, Pro answers: 10 minutes
    3. Error-handling patterns for scripts Intermediate Free lesson, Pro answers: 10 minutes
    4. Debugging: bash -x, PS4, trap DEBUG and logs Intermediate Free lesson, Pro answers: 10 minutes
  10. Module 11

    Text processing: the Unix toolbox

    The Unix text toolbox from the shell: sort, uniq, grep, regular expressions, sed, awk, find and xargs, jq for JSON, CSV and TSV, dates and numbers.

    1. cut, tr, head, tail, wc, paste and friends Beginner Free lesson, Pro answers: 5 minutes
    2. sort and uniq: counting and top-N reports Intermediate Free lesson, Pro answers: 10 minutes
    3. grep: searching text and files Beginner Free lesson, Pro answers: 10 minutes
    4. Regular expressions for grep, sed and awk Intermediate Free lesson, Pro answers: 10 minutes
    5. sed: substitute, delete and print Intermediate Free lesson, Pro answers: 10 minutes
    6. sed beyond s///: hold space and multiline Advanced Free lesson, Pro answers: 25 minutes
    7. awk: fields, patterns and actions Intermediate Free lesson, Pro answers: 15 minutes
    8. awk programs: arrays, joins and reports Advanced Free lesson, Pro answers: 10 minutes
    9. find and xargs: working with many files Intermediate Free lesson, Pro answers: 15 minutes
    10. jq: query and reshape JSON from the shell Intermediate Free lesson, Pro answers: 15 minutes
    11. CSV, TSV and YAML from the shell Intermediate Free lesson, Pro answers: 10 minutes
    12. Dates, times and non-integer numbers Intermediate Free lesson, Pro answers: 20 minutes
  11. Module 12

    Processes, jobs and signals

    Subshells and the execution environment, background jobs and wait, job control, signals, kill and timeout, named pipes and coprocesses.

    1. Subshells and the execution environment Intermediate Free lesson, Pro answers: 10 minutes
    2. Background jobs, wait and parallel work Intermediate Free lesson, Pro answers: 10 minutes
    3. Job control: Ctrl-Z, fg, bg, jobs, disown Beginner Free lesson, Pro answers: 10 minutes
    4. Signals, kill and timeout Intermediate Free lesson, Pro answers: 15 minutes
    5. Named pipes and coprocesses Advanced Free lesson, Pro answers: 15 minutes
  12. Module 13

    The interactive shell

    Startup files and PATH, history and readline, the prompt, aliases and completion for a faster everyday shell.

    1. Startup files, PATH and login shells Intermediate Free lesson, Pro answers: 5 minutes
    2. History, Ctrl-R and readline editing Beginner Free lesson, Pro answers: 5 minutes
    3. Prompt, aliases, dirstack, completion Intermediate Free lesson, Pro answers: 5 minutes
  13. Module 14

    Portability: POSIX sh, versions and platforms

    POSIX sh versus Bash, the POSIX.1-2024 shell changes, GNU versus BSD tools on Linux and macOS, and checking Bash versions and features.

    1. POSIX sh vs Bash: spotting and fixing bashisms Intermediate Free lesson, Pro answers: 15 minutes
    2. What POSIX.1-2024 changed for shell scripts Intermediate Free lesson, Pro answers: 15 minutes
    3. GNU vs BSD tools: Linux and macOS differences Intermediate Free lesson, Pro answers: 15 minutes
    4. Bash 3.2 to 5.3: versions and feature checks Intermediate Free lesson, Pro answers: 10 minutes
  14. Module 15

    Security for shell scripts

    Avoiding injection through eval and untrusted input, and secure scripting practices for files, temporary paths, permissions and secrets.

    1. Injection, eval and untrusted input Intermediate Free lesson, Pro answers: 15 minutes
    2. Secure scripting: temp files, secrets and PATH Advanced Free lesson, Pro answers: 15 minutes
  15. Module 16

    Quality: ShellCheck, tests, style and speed

    ShellCheck static analysis, testing scripts with Bats, style for maintainable scripts, and making scripts faster by avoiding needless forks.

    1. ShellCheck: catch bugs before a script runs Beginner Free lesson, Pro answers: 10 minutes
    2. Testing Bash scripts with Bats Intermediate Free lesson, Pro answers: 10 minutes
    3. Style and maintainable scripts Intermediate Free lesson, Pro answers: 10 minutes
    4. Fast Bash: builtins, forks and measuring Advanced Free lesson, Pro answers: 15 minutes
  16. Module 17

    Scripts in the real world

    Scheduled jobs with cron, shell in CI, containers, make and hooks, logging, locking and idempotent scripts, archives, backups and remote work.

    1. cron: scheduling scripts that actually run Intermediate Free lesson, Pro answers: 20 minutes
    2. Shell in CI, Docker, Makefiles and Git hooks Intermediate Free lesson, Pro answers: 20 minutes
    3. Logging, locking and idempotent scripts Advanced Free lesson, Pro answers: 15 minutes
    4. Archives, checksums and backups Intermediate Free lesson, Pro answers: 20 minutes
    5. Remote work: ssh, rsync and curl in scripts Intermediate Free lesson, Pro answers: 20 minutes
  17. Module 18

    Choosing tools and interview preparation

    When Bash is the right tool and when another language fits better, and preparing for shell scripting interview questions.

    1. When to use Bash, and when to switch to Python Beginner Free lesson, Pro answers: 20 minutes
    2. Shell scripting interview questions, explained Intermediate Free lesson, Pro answers: 15 minutes

Related tools

Official documentation

More in Programming languages

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.