Topic

Bash

Bash guides from Tryssh: practical diagnostics, safe operating procedures, and production runbooks for server operators.

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.

The Tryssh team · July 29, 2026

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.

The Tryssh team · July 29, 2026

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.

The Tryssh team · July 29, 2026

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.

The Tryssh team · July 29, 2026

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.

The Tryssh team · July 29, 2026

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.

The Tryssh team · July 29, 2026

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.

The Tryssh team · July 29, 2026

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.

The Tryssh team · July 29, 2026

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.

The Tryssh team · July 29, 2026

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.

The Tryssh team · July 29, 2026