Перейти к содержимому

Bash Scripting I: Variables, Quoting & Loops | Zero to LLMOps (Day 22)

Zero to LLMOps

0:00 / 0:00

Bash Scripting I: Variables, Quoting & Loops | Zero to LLMOps (Day 22)

34 просмотра · 2 нед. назад
Zero to LLMOps
64 подписчика
34 просмотра · 2 нед. назад
Day 22 of a free 180-day DevOps course. Welcome back to Zero to LLMOps! Today begins Week 4 in Phase 1 (Foundations), transitioning from interactive commands to reliable, production-grade automation in Bash. A single unquoted variable causes catastrophic production outages. When a script runs rm -rf $TARGET_DIR/* and TARGET_DIR is unset due to an environment typo, Bash expands it to rm -rf /*! In this session, master defensive quoting rules, extended test syntax, branching patterns, and line-by-line file loops for hardened production scripts. What we cover today: • Part A — Variables & Quoting: "$var" (expands, preserves whitespace) vs '$var' (literal) vs unquoted $var (word-splitting danger). Special variables: $0, $1-$9, $#, $@, $?, and $$. • Part B — Conditional Testing: POSIX [ ] vs Extended [[ ]], file tests (-f, -d, -s), string tests (-z, -n), numeric tests (-eq, -ne, -lt, -gt), and logical operators (&& and ||). • Part C — Branching Flow: if/elif/else blocks with semicolons, and case statements for clean CLI option dispatchers. • Part D — Loops & File Processing: Looping over ranges {1..5} and globs (*.log), the "never loop over ls" rule, and line-by-line streaming with while IFS= read -r. • Incident & LLMOps Parallel: The rm -rf $TARGET_DIR/* outage when unset, and preserving escaped JSON prompt strings in LLM pipelines. • Hands-on Lab: Building ~/scripts/checkfile.sh (file audit) and ~/scripts/svcctl.sh (service controller). ⏱ Chapters 00:00 Intro: Moving from Shell Commands to Software Engineering 00:43 Day 22 Roadmap: Variables, Quoting Rules, Conditions & Loops 01:24 Recall Warm-Up: Days 19-21 Review (DAC vs MAC, chcon, nginx -t, firewalld) 03:07 Terminal Baseline: Checking Bash Shell & Version (GNU bash v5) 03:26 Part A: Variables & Quoting: The Single Most Consequential Shell Habit 04:02 Double vs Single vs No Quotes & Word-Splitting Disasters 05:13 Special Variables ($0, $1-$9, $#, $@, $?, $$) 05:38 Terminal Demo: Quoting Filenames with Spaces 06:23 Part B: Conditional Testing: POSIX [ ] vs Bash Extended [[ ]] 07:26 Common Test Flags: File Tests (-f, -d, -e, -s) & String Tests (-z, -n) 08:05 Numeric Comparison: Why -eq, -ne, -lt, -gt instead of symbols 09:28 Part C: Branching Control Flow: if/elif/else vs case Statements 10:30 Part D: Loops & Line-by-Line File Processing (while read -r) 11:49 Production Incident: The rm -rf $TARGET_DIR/* Catastrophe 12:26 LLMOps Parallel: Preserving JSON Prompts with while IFS= read -r 13:03 Hands-on Lab Part 1: Variables & Quoting Drills (Fixing for f in *) 14:06 Hands-on Lab Part 2: [[ ]] Extended Tests & Numeric Comparisons 15:02 Hands-on Lab Part 3: Writing checkfile.sh (if/elif/else) & svcctl.sh (case) 15:50 Hands-on Lab Part 4: Loops & Processing Logs with while read -r 16:21 Session Recap: Core Bash Syntax & Quoting Rules 17:16 Homework: 6 Spaced-Repetition Recall Questions for NotebookLM 17:58 Day 23 Preview: Bash Functions, Positional Args, Exit Codes & Traps Definition of Done: 1. Explained quoting differences: "$var", '$var', and unquoted $var. 2. Verified all 6 special shell variables ($0, $1-$9, $#, $@, $?, $$). 3. Replaced legacy [ ] tests with Bash extended [[ ]] in scripts. 4. Built and tested ~/scripts/checkfile.sh (if/elif/else). 5. Built and tested ~/scripts/svcctl.sh (case matching). 6. Streamed logs line-by-line using while IFS= read -r. 7. Completed all 6 homework questions in your study journal. 📚 FREE COURSE MATERIAL — every lesson, lab and answer key: https://github.com/mahadikabhijeet/ze... All 185 written lessons, labs, and study guides are on GitHub, free and open. ◀ Previous — Day 21: Week 3 Review (Consolidation Quiz & Project Audit) ▶ Next — Day 23: Bash Scripting II (Functions, Positional Args, Exit Codes & Traps) 🔔 Subscribe for the full path from zero to LLMOps. #Bash #Linux #DevOps #SysAdmin #ShellScripting #SRE #LearnLinux #Automation #LLMOps #ZeroToLLMOps