Bash Array Bulk Operations
Manipulate indexed arrays safely with quoted expansion, slice and search builtins, and mapfile ingestion so filenames with spaces survive round trips.
Manipulate indexed arrays safely with quoted expansion, slice and search builtins, and mapfile ingestion so filenames with spaces survive round trips.
Poll a flaky JSON endpoint with curl retry flags, fail fast on HTTP errors, and extract fields with jq without leaving the pipeline.
Run CPU-bound jobs in parallel with xargs -P, cap concurrency to core count, and keep per-job logs separated for post-mortem.
Create an isolated temp workspace with mktemp -d and guarantee removal through an EXIT trap even when the script is interrupted.
Group and count items using a bash associative array as a frequency map with iteration over sorted keys.
Use awk to aggregate fields by key with conditional logic and formatted output for log analysis.
Process files in batches using find with exec and a batch size limit to avoid argument list overflow.
Parse command line options using bash getopts with validation, default values, and usage messages.
Generate a config file from a here document template with variable expansion and command substitution.
Run background jobs in parallel with a concurrency limit and wait for all to complete collecting exit statuses.
Use bash parameter expansion for default values, substring extraction, and pattern removal in a single script.
Compare two command outputs without temp files using bash process substitution with the diff command.
Use bash regex conditional matching with BASH_REMATCH to extract capture groups from structured input strings.
Perform in place stream editing with sed using a backup suffix and multiple expression commands for safe text transformation.
Register a trap handler to clean up temporary resources on exit, interrupt, and termination signals.
Parse CLI subcommands and options with getopts for shell script tooling.
Assert that reproducibility-critical environment variables are pinned before a build, failing fast when they are not.
Retry a shell command with exponential backoff and a bounded attempt count, failing loudly when exhausted.
Parse short options and their arguments with getopts so a shell script exposes a predictable CLI instead of positional guesswork.
Aggregate CSV columns with awk: per-group sums, counts, and computed ratios in one pass over streaming input.
Structure script output with a logger function: level filtering, stderr separation, timestamps, and color-aware terminals.
Turn a header CSV into newline-delimited JSON by streaming rows through awk and jq, preserving the header as field names.
Retry curl against flaky endpoints with retry flags, exponential backoff, and server-side Retry-After header respect.
Script a full container release flow: build with cache pins, tag by digest and git SHA, push, and wait for registry health.
Validate required environment variables upfront with parameter expansion guards, checking formats before any side effects.
Scan a directory tree, sort files by size, and print the largest offenders so disk pressure can be investigated quickly.
Prevent concurrent script runs with flock on a lockfile, distinguishing owner from contenders and timing out politely.
Parse long and short options robustly with getopt, validating required flags, defaults, and positional arguments.
Enforce quality gates with a pre-commit hook running lint and format checks, mirrored by the CI pipeline stages.
Transform JSON on the command line with jq filters, selecting fields, reshaping objects, and aggregating arrays in pipes.
Retry a shell command that may fail transiently, waiting longer between attempts and reporting the last error when all tries are exhausted.
Poll rate-limited APIs politely with sleep pacing, exponential spacing for empty results, and a hard attempt ceiling.
Start scripts with strict mode settings so unset variables, failing commands, and pipe errors stop execution instead of being silently ignored.
Harden shell scripts with set -euo pipefail and an ERR trap, converting silent failures into loud, traceable exits.
Emit log lines with a UTC timestamp, level, and message from one helper, so shell output stays consistent and easy to parse.
Stream growing log files with tail -F and grep pipelines, highlighting patterns and stopping cleanly on signals.
Bound external commands with the timeout utility, distinguishing exit code 124 from genuine failures and retrying on it.
Guarantee resource cleanup on any exit path with traps for EXIT INT TERM, keeping partial work dirs off the filesystem.
Register a trap so temporary files and processes are cleaned up even when the script fails or is interrupted.
Poll a health endpoint until a dependency is ready or a timeout elapses, preventing a start-up script from racing ahead of its services.
Process file batches in parallel with xargs -P and -N, controlling concurrency, preserving order, and capping memory.
Enumerate and prune files with find -print0 and read -d '' so spaces, quotes, and newlines in filenames cannot break the script.
Guarantee one cron job at a time with a flock file descriptor, a bounded wait, exit code 75, and cleanup that always unlocks.
Parse short options with getopts, distinguish missing arguments from unknown flags, then validate exactly two positional paths.
Create a private temp directory with mktemp and remove it reliably from an EXIT trap, preserving the original exit status and signals.
Performs arithmetic operations using $(( )), let, and expr including integer math, bitwise operations, increment/decrement, and conditional expressions.
Demonstrates indexed arrays in Bash including declaration, iteration, slicing, appending, sorting, and filtering with practical data processing examples.
Uses Bash associative arrays (hash maps) for key-value storage, iteration, lookup, and data aggregation with practical configuration and counting examples.
Uses case statements with glob patterns, fall-through behavior, and default cases for implementing command dispatch and input classification logic.
Uses command substitution to capture command output, nest substitutions, and combine with variable assignment for dynamic script behavior.
Demonstrates if/elif/else conditionals with test commands, file tests, string tests, numeric comparisons, and logical operators in Bash scripts.
Demonstrates proper exit code handling, error checking, set options for fail-safe behavior, and custom exit codes for script error reporting.
Performs file and directory operations including creation, copying, moving, permission management, and safe file handling with proper error checking.
Uses the find command with various predicates, actions, and exec options to locate, filter, and process files based on metadata and patterns.
Defines and uses Bash functions with local variables, return values, argument passing, and recursive calls for modular and reusable script logic.
Uses getopts to parse command-line options with short flags, default values, and argument validation for building robust CLI tools in Bash.
Uses here documents and here strings to feed multi-line text to commands, generate config files, and create inline data for script processing.
Demonstrates for loops, while loops, until loops, and C-style loops with break, continue, and range iteration for various data processing patterns.
Manages background jobs with &, wait, jobs, and process control for parallel task execution and synchronization in Bash scripts.
Demonstrates advanced Bash parameter expansion patterns including defaults, alternatives, substring, case modification, and variable indirection.
Constructs multi-stage pipelines connecting commands with pipes for data transformation, filtering, and aggregation in a streaming fashion.
Uses process substitution to feed command output as files to commands expecting file arguments, enabling complex data comparison and merging operations.
Demonstrates stdin, stdout, stderr redirection including appending, merging streams, discarding output, and using file descriptors for advanced I/O control.
Uses Bash regex matching with the =~ operator for pattern validation, extraction, and conditional logic including email, IP, and URL validation.
Uses sed for stream editing and awk for field-based processing to transform, filter, and extract data from text files and command output.
Handles Unix signals in Bash scripts using trap, kill, and wait for graceful shutdown, timeout enforcement, and inter-process communication.
Demonstrates Bash string manipulation including substring extraction, pattern replacement, case conversion, trimming, and splitting operations.
Sets up trap handlers for signals like EXIT, INT, TERM, and ERR to ensure cleanup, graceful shutdown, and error recovery in Bash scripts.
Demonstrates variable expansion, quoting rules, and special variables in Bash including single vs double quotes and command-line arguments.
Uses xargs to build and execute commands from standard input with parallel execution, argument batching, and null-delimiter handling for safe processing.