Pass Bash arrays without collapsing arguments or expanding globs
Quoted per-element array expansion preserves each member as one argument, while unquoted or star forms can split and glob data.
Use Bash errexit only after understanding the contexts that suppress it
Errexit exits on certain unhandled nonzero statuses, but conditional lists, pipelines, functions, subshells, and command substitutions change its behavior.
Use flock to prevent overlapping Bash jobs without stale PID files
Flock asks the kernel to hold an advisory lock on a file descriptor or path for the process lifetime, avoiding manual stale-PID cleanup.
Parse Bash script options with getopts and reject ambiguous input
Getopts consumes short options according to an optstring, sets OPTARG and OPTIND, and leaves remaining positional arguments for explicit validation.
Distinguish unset, empty, default, and required Bash variables
Colon forms of parameter expansion test both unset and null values, while non-colon forms test only unset; assignment and error operators have additional effects.
Preserve the first meaningful pipeline failure with Bash pipefail
Without pipefail a pipeline normally returns the last command status; with pipefail it returns the rightmost nonzero status and PIPESTATUS retains each component.
Read file lines in Bash without losing backslashes or the last record
IFS= read -r preserves leading whitespace and backslashes, while an additional condition handles a final line without newline.
Bound remote command runtime while distinguishing timeout from remote failure
GNU timeout sends a signal after a duration and returns a timeout-specific status; SSH and the remote child have separate connection and execution lifetimes.
Build a Bash cleanup trap that preserves the original exit status
A trap runs shell code when specified signals or EXIT occur; cleanup must capture status, avoid recursion, and handle partially initialized resources.
Debug Bash with xtrace without printing credentials
Xtrace prints expanded commands after substitutions, so secrets in variables, arguments, URLs, and generated headers can reach logs even when source code looks safe.