getopts in Bash: Parse Command-Line Options Properly
A tested getopts skeleton for Bash scripts: flags, options with values, required options, error handling, and a manual loop for --long options.
Archive
A tested getopts skeleton for Bash scripts: flags, options with values, required options, error handling, and a manual loop for --long options.
A persistent WordPress object cache for hosting without Redis: each entry is a PHP file that OPcache keeps compiled. How it works, and what it did on a test site.
Store IPv4 addresses as INT UNSIGNED and test CIDR membership with a bitmask or, much faster on a big table, an indexed BETWEEN range on network and broadcast.
set -euo pipefail is good advice, but each option has rules about when it fires. Here is what each one does and the cases that surprise people.
while IFS= read -r line is the correct loop, but the last line, pipes, commands that read stdin and Windows line endings each have a trap. Here they are, tested.
PHP-compatible str_pad() in pure Bash, when printf "%-10s" and %05d are enough, and why multibyte text breaks the alignment of your columns.
A correct in_array() for Bash, an associative-array set for many lookups, and a demonstration of why [[ "${arr[*]}" =~ value ]] gives false positives.
Two small functions that stop search boxes and scroll handlers from running too often, with a runnable timeline that shows exactly when each one fires.
PHP's explode() and implode() in Bash: read -ra and mapfile -d for splitting, "${arr[*]}" for joining, and functions that cope with multi-character delimiters.
What the backend really receives behind nginx: proxy_pass URI rewriting, Host and X-Forwarded headers, WebSocket upgrades, 504s from timeouts, and streaming.