jvinhit//lab

Search posts

Type to search across journal entries.

navigate open esc close

Series · 10 parts

Bash & Shell Scripting

From your first script to production-grade automation — quoting, loops, functions, text processing, and robust error handling.

  1. Start scripting from zero: what a shell really is, bash vs sh, the shebang line, making a script executable, the three ways to run it, echo vs printf, and exit codes — bilingual, with exercises.

  2. Variables without spaces around =, quoting rules, ${var} braces, command and arithmetic expansion, positional args, defaults, export, and why "$var" beats bare $var — bilingual, with exercises.

  3. Master bash conditionals: if runs on exit codes (0 = true), test vs [[ ]], file/string/numeric operators, && || short-circuit, and case patterns — bilingual, with exercises.

  4. Master bash loops: for-in over lists and files, C-style for, while/until, safe line-by-line reading with IFS= and read -r, process substitution vs pipes, break/continue, and brace expansion — bilingual, with exercises.

  5. Bash functions: define with name() or function, pass $1/$@, return exit codes not strings, capture output with $(), scope with local, source library files — bilingual, with exercises.

  6. Indexed and associative bash arrays, string slicing, prefix/suffix removal, search/replace, case conversion, safe iteration, and parameter defaults — bilingual, with exercises.

  7. Master bash I/O: stdin/stdout/stderr, > and >>, 2>&1 order traps, /dev/null, here-docs, pipes, tee, and read — bilingual, with a comparison table and exercises.

  8. grep, sed, and awk for shell text processing: flags, substitution, field parsing, cut/sort/uniq/tr/wc pipelines — bilingual, with real log pipelines and exercises.

  9. Harden bash scripts with set -euo pipefail, traps, mktemp cleanup, die(), IFS, set -x debugging, ShellCheck, and idempotency — bilingual, with a comparison table and exercises.

  10. Capstone: getopts, usage(), script structure, logging, env config, and a production-grade backup script with traps and validation — plus best practices and when NOT to use bash. Bilingual exercises.