Comment by burnt-resistor

20 days ago

    #!/usr/bin/env bash
    set -eEuo pipefail # pipefail bash 4.2+, which is basically everything. There's a longer version for backwards compatibility, but it's rare.

    die() {
      echo >&2 "ERROR: $*"
      exit 1
    } 

    # e= & exit preserves the original exit code
    # trap - ... prevents multiple cleanup() calls
    # To only run on error instead of always, replace both EXITs with ERR
    trap 'e=$?; trap - EXIT; cleanup; exit $e' EXIT
    cleanup() {
      : # Delete this line and place cleanup code here.
    }

    # Minimal script here.
    # Use semantic-named functions.
    # DRY.
    # Don't use many levels of indentation.
    # All ordinary variables must be defined before use, so use checks like [[ -n "${X-}" ]]
    # All pipeline and bare command non-zero exit codes are errors.