Skip to content
academia.sh

Course Intermediate

Shell Programming

By the end of this course

Start course

01

Streams and Pipelines

The three standard streams, redirection operators, chaining commands with a pipeline, input embedded in a script, and the exit status convention.

  1. 01 Standard Input, Output, and Error The three standard streams, file descriptor numbers, separating a command's data from its diagnostics, and the filter model.
  2. 02 Redirection Redirection operators, the difference between truncating and appending, descriptor duplication and the importance of order, overwrite-protection traps.
  3. 03 The Pipeline The pipe operator, concurrent process execution, pipe buffering and backpressure, the chain's exit status, and variables lost in a subshell.
  4. 04 Here Documents and Here Strings Input embedded in a script, the effect of quoting the delimiter on expansion, indentation removal, and single-line input notation.
  5. 05 Exit Status The success/failure convention, reserved code ranges, conditional chaining operators, and why these operators are not confused with conditional branching.

02

Script Structure

The building blocks of a shell script, from the shebang to variable expansion, from quoting rules to conditions, loops, functions, and arrays.

  1. 01 Script Anatomy The shebang, execute permission, the three ways to run a script, and the difference between a subprocess and sourcing.
  2. 02 Variables and Quoting Rules Assignment syntax, expansion order, word splitting and pathname expansion, the three quoting forms, and default-value expansions.
  3. 03 Special Variables and Arguments Positional parameters, the two representations of the argument list, the loop that consumes the list, and option parsing.
  4. 04 Conditions and Tests A condition being an exit code, file/string/number tests, the parsing difference between single and double brackets, pattern matching, and multi-way selection.
  5. 05 Loops List-, counter-, and condition-based iteration, safely iterating over file names, the correct form of reading line by line, and loop control.
  6. 06 Functions and Scope Function definition, argument passing, the distinction between returning an exit code and returning a value, local variables, and dynamic scope.
  7. 07 Arrays and Associative Arrays Definition of indexed and associative arrays, bulk expansion, sparseness, single-pass counting, and checking version dependency.
  8. 08 Arithmetic and Command Substitution Integer arithmetic and its traps, the arithmetic command's inverted exit code, offloading decimal calculation, and turning command output into a value.

03

Text Processing

Regular expressions, line filtering, stream editor transformation, field-based processing, sorting and deduplication, and column-level transformations.

  1. 01 Regular Expressions The basic-versus-extended syntax distinction, quantifiers, anchors and bracket expressions, greediness, and portable character classes.
  2. 02 Line Filtering Selecting, counting, and inverting lines by pattern, word and full-line matching, fixed string mode, multi-file search, and using the exit code as a condition.
  3. 03 Transforming with the Stream Editor The substitution command and its flags, rewriting with backreferences, address and range selection, and the mismatch between implementations in in-place editing.
  4. 04 Field-Based Processing The record and field model, the pattern–action structure, built-in variables, accumulation with associative arrays, and producing a report in a single pass.
  5. 05 Sorting, Deduplication, and Joining Sorting by key, the effect of the locale on sort order, deduplication that requires adjacency, and set operations over sorted streams.
  6. 06 Cutting, Pasting, and Splitting Column cutting and its limits, pasting files side by side, character-level transformation, splitting a file into pieces, and the tool-selection criterion.

04

Writing Robust Scripts

Strict mode options, catching signals and cleanup, debugging with trace mode, static analysis, and scheduled tasks.

  1. 01 Error Handling Strict mode options, the scope and exceptions of early exit, undefined variable checking, pipeline exit codes, and the error-catching hook.
  2. 02 Traps and Cleanup The concept of a signal, setting traps, a cleanup hook that runs on exit, the safe creation of temporary files, and a lock that prevents concurrent runs.
  3. 03 Script Debugging Syntax checking, trace mode and prompt formatting, redirecting the trace, and inspecting variables and the call stack.
  4. 04 Static Analysis Finding errors without running the script, common shell error classes, portability checking based on the interpreter declaration, and the correct use of warning suppression.
  5. 05 Scheduled Tasks Reading a cron entry, how the scheduler's environment differs from an interactive shell, managing output, and a wrapper that prevents overlap.

Start typing to search.

↑↓ Esc navigate · open · close