Welcome to my personal Bash reference repository! 🎯 This repository contains a curated, comprehensive, and progressive collection of 59 practical examples that document my journey into learning and mastering Linux shell scripting for DevOps.
The repository transitions smoothly from absolute syntax fundamentals to advanced task automation, programmatic logic, and heavy-duty text processing.
The codebase is strictly structured into 6 sequential modules. Each directory represents a higher level of complexity:
Focused on fundamental environment syntax and operations.
- 01 to 05: Shebang initialization (
#!/bin/bashvs#!/usr/bin/env bash), shell execution methods, and file permissions (chmod +x). - 06 to 08: Literal preservation via Single Quotes (
' ') vs variable expansion via Double Quotes (" "), and character escaping (\$). - 09 to 11: Static and dynamic variable evaluation (e.g., date-based strings for backups) and core integer arithmetic operations.
Focused on programmatic decision making and validations.
- 12: Basic directory checking (
if/elseconditions). - 13 & 14: Comparative analysis between classic test brackets
[ ](vulnerable to word splitting) and modern bash brackets[[ ]](space-safe). - 15 & 16: String length validation (
-zfor empty inputs) and runtime user identity mapping (root user enforcement via UID checking). - 17 & 18: Advanced file property validations (
-f,-r,-s) combined with multi-logical gates (||,!), leading into the foundational syntax ofcaseswitches.
Focused on iterative data streaming and parameter management.
- 19: Practical service control script template leveraging argument input (
$1) parsed through acasestate machine. - 20 to 22: Deep dive into loop variables and the critical operational difference between unquoted expansions vs quoted strict arrays (
$*vs"$*"vs$@vs"$@"). - 23 to 25: Automation patterns including bulk file extension renaming, iterative batch user creation, and target Kubernetes pod eviction based on parsed logs.
- 26 to 28: Analyzing the
for-catstream anti-pattern vs the canonicalwhile IFS= read -rapproach for processing files line-by-line, concluded by service health checking using anuntilloop.
Focused on modularity, variable scopes, and loop control states.
- 29 & 30: Functional declarations, sandboxing data using the
localkeyword, and string output capturing. - 31 to 34: Implementing immediate break signals inside active scanners, optimizing loop skips using
continue, and breaking out of multi-layered nested loops seamlessly viabreak 2.
Focused on compound structural data design.
- 38 to 41: Instantiating Indexed Arrays, element address extraction, array counting elements (
${#array[@]}), and dynamic element appending (+=). - 42 to 48: Simulating and fixing edge cases involving string array iteration containing unescaped whitespaces using exact index parsing.
- 49 to 52: Constructing Key-Value structures via Associative Arrays (
declare -A), extracting map keys via"${!array[@]}", and querying key existences via-v.
Focused on processing production data and parsing text logs.
- 53 to 55: Building an end-to-end telemetry log analysis tool using an associative counter map fed by a file stream to yield structured data statistics.
- 56: Regular expressions engine mapping IPv4 patterns from authentication server security logs via
grep -E -o. - 57: Stream manipulation via
sedto search, inject config backups (-i.bak), and dynamically alter active network daemon properties. - 58 & 59: Columnar relational layout data extraction from system database matrices (
/etc/passwd), alongside runtime structural evaluations (adding arithmetic byte sums) natively inawk.
To explore or debug these configurations within a local environment, follow these standard steps:
-
Clone the repository locally:
git clone https://github.com cd bash-scripting-portfolio -
Grant execution permissions to the target script:
chmod +x 01-basics/10-dynamic-backup-dir.sh
-
Execute the script:
./01-basics/10-dynamic-backup-dir.sh
Built with high attention to shell safety, POSIX compliance best practices, and clean documentation.
- Automated Server Health Checker: A production-ready Bash script designed to safely monitor remote servers via SSH, using strict mode, trap handlers, and secure argument parsing.