Skip to content

Run a command with status

Print, execute, and report a non-zero status; pause when interactive.

18th August 2026

run_cmd() {
  local status=0
  printf "\n==> %s\n\n" "$*"
  "$@" || status=$?
  if [ "${status}" -ne 0 ]; then
    printf "\nCommand exited with status %s.\n" "${status}"
  fi
  if [ "${INTERACTIVE}" -eq 1 ]; then
    pause
  fi
  return "${status}"
}

Caveats

Expects INTERACTIVE to be 0 or 1. When interactive, calls pause — include that function too.