DevOps · 5 modules

Bash & Shell Scripting

The parts of Bash that bite in production: quoting, parameter expansion, exit codes and redirection order. Learn why "$@" is not "$*", what set -euo pipefail buys you, and why 2>&1 >file does not do what it looks like — remembered with spaced repetition.

flashcards
50
flashcards
per day
~10 min
per day
level
Beginner → Intermediate
level
modules
5
modules
About this topic

What this track is for

Shell scripts fail quietly. An unset variable expands to nothing and a command runs against the wrong path; a pipeline reports success because only its last stage mattered; a loop on the right-hand side of a pipe updates variables in a subshell that then disappears. None of these produce an error — they produce a wrong result that looks like a right one.

This track is built around those failure modes. It covers the quoting and expansion rules that decide whether an argument survives as one word, the difference between ${var:-default} and ${var:=default}, why [[ ]] protects unquoted variables from word-splitting where [ ] does not, and what set -euo pipefail and trap actually change about how a script dies.

The remaining modules cover redirection and process substitution — including the left-to-right ordering that makes 2>&1 >file behave differently from >file 2>&1 — and the text tooling scripts lean on daily: grep, sed, awk, cut and uniq. Every card is grounded in the GNU Bash reference manual.

What you'll learn

5 modules, seed to bloom

Each module is a set of flashcards — 50 in total. Answer, review, and watch your knowledge grow from seed to full bloom.

Variables, Quoting & Expansion

Parameter expansion, defaults, string operators, arrays, and single vs double quoting

10 cards

Conditionals & Loops

test and [[ ]], numeric vs string comparison, pattern and regex matching, case, for, while and until

10 cards

Functions, Exit Codes & Error Handling

Exit status, set -euo pipefail, trap, local scope, return values and positional parameters

10 cards

Pipes, Redirection & Process Substitution

Stdout and stderr, truncate vs append, 2>&1 ordering, here-strings, process substitution and pipe subshells

10 cards

Text Tooling in Scripts

Everyday grep, sed, awk, cut, sort and uniq patterns for scripting pipelines

10 cards
Try before you plant

Sample questions

A taste of the real flashcards. Pick an answer, then reveal the explanation.

Sample · Bash & Shell Scripting

Inside double quotes, how do "$@" and "$*" differ?

  • A"$@" expands each positional parameter as a separate word, "$*" joins them into one
  • B"$@" joins all positional parameters into one word, "$*" expands each separately
  • C"$@" expands only the first positional parameter, "$*" expands every one after it
  • D"$@" strips empty positional parameters entirely, "$*" keeps them as blank words
Permalink & share
Sample · Bash & Shell Scripting

Why is [[ ... ]] generally preferred over [ ... ] in Bash scripts?

  • A[[ is a shell keyword that avoids word-splitting and globbing of unquoted variables
  • B[[ is an external program that runs measurably faster than the builtin [ command
  • C[[ automatically converts its string operands to numbers before comparing them
  • D[[ is the only construct able to test whether a file exists on the disk
Permalink & share
Sample · Bash & Shell Scripting

Why do robust scripts commonly begin with set -euo pipefail?

  • ATo fail fast on errors, on unset variables, and on failures anywhere in a pipeline
  • BTo silence all command output, disable history, and speed up command execution
  • CTo enable verbose tracing, keep running past errors, and log output to syslog
  • DTo run the whole script with elevated privileges and a tightly restricted PATH
Permalink & share
Sample · Bash & Shell Scripting

Why does command 2>&1 >file still leave error output on the terminal?

  • Astderr copies stdout's terminal target before stdout is later moved to the file
  • Bstderr is inherently immune to redirection and can only ever reach the terminal
  • CA file cannot hold two streams, so stderr silently falls back to the terminal
  • DThe shell applies >file first, redirecting stderr before stdout is redirected
Permalink & share
How Gnoseed works

Learn it once, keep it for good

1

Answer a question

Each card is one practical concept with multiple options. Pick what you think is right.

2

Get the full answer

See the correct option plus a clear explanation, and a link to deeper docs when one is available.

3

Review at the right time

A spaced-repetition engine (SM-2 or FSRS) resurfaces each card just before you would forget it.

Why learn this

Why this material is worth your time

Quoting you can defend in review

"$@" forwards arguments intact, "$*" flattens them into one. That single distinction prevents a whole category of bugs with filenames containing spaces.

Failure that is actually loud

set -e, set -u and pipefail each catch a different silent failure, and trap gives you cleanup that runs even when the script exits early.

Redirection order, understood once

Redirections apply left to right against the target a stream points at right now. Learn that and the classic 2>&1 confusion resolves permanently.

Expansion instead of extra processes

${file%.txt}, ${str//foo/bar} and ${#name} do in the shell what most scripts fork sed or basename for — shorter, faster, and harder to get wrong.

FAQ

Common questions

Is this Bash specifically, or POSIX sh? +

Bash. Several of the constructs covered — [[ ]], arrays, <(process substitution), ${str//foo/bar} — are Bash extensions and are not available in a plain POSIX shell. Where that matters, the cards say so.

Do I need to know Linux commands first? +

Basic familiarity helps — you should be comfortable at a prompt. The track is about the shell language and its semantics rather than a tour of commands; the Linux tracks cover the command-line surface itself.

Does it help with the LPIC-1 exams? +

Indirectly. Shell scripting is part of LPIC-1 exam 102, so this track reinforces it, but it is written around writing robust scripts rather than around the exam objectives. The LPIC-1 tracks map to those directly.

Is it free? +

Yes, completely free. No registration or credit card is required, and all your progress is stored locally in your browser.

Ready to write scripts that fail loudly?

Plant your first seed today. Ten minutes a day turns shell folklore into rules you can explain.

Start learning free