Die

cmd_die

Print a formatted error message and terminate the script by sending SIGTERM to the top-level PID. Safe to call from subshells. Uses colour when stderr is a terminal.

Arguments

  • ... (string): Error message text

Exit codes

  • 1: Always (via SIGTERM trap)

Output on stderr

  • Formatted error message prefixed with script name and line number

die

Alias for cmd_die.

cmd_warn

Print a formatted warning message to stderr and return (non-fatal). Uses colour when stderr is a terminal.

Arguments

  • ... (string): Warning message text

Exit codes

  • 0: Always

Output on stderr

  • Formatted warning message prefixed with script name and line number

warn

Alias for cmd_warn.

cmd_try

Run a command and die with a descriptive message if it fails. A lightweight alternative to cmd_exec() for critical one-liners.

Arguments

  • ... (string): The command and its arguments to execute

Exit codes

  • 0: Command succeeded
  • 1: Command failed (via cmd_die())

try

Alias for cmd_try.

cmd_retry

Run a command up to N times until it succeeds. Prints a dot to stderr for each failed attempt. Optionally sleeps between attempts with -s.

Arguments

  • $1 (string): Optional: '-m N' max attempts (default: 3)
  • $2 (string): Optional: '-s N' sleep seconds between attempts (default: 0)
  • ... (string): The command and its arguments to execute

Exit codes

  • 0: Command succeeded within the allowed attempts
  • 1: All attempts exhausted

Output on stderr

  • A dot per failed attempt, then a newline; error message if exhausted