DEV Community

Query Filter
Query Filter

Posted on

failed

#!/usr/bin/env bash

failed=()   # array of names

run_job() {
  local name="$1"
  shift

  "$@"
  rc=$?

  if (( rc != 0 )); then
    failed+=("$name")
  fi
}

# examples
run_job job1 false
run_job job2 true
run_job job3 ls /does/not/exist

# print results
if (( ${#failed[@]} > 0 )); then
  echo "Failed jobs:"
  for n in "${failed[@]}"; do
    echo "  $n"
  done
else
  echo "All jobs succeeded"
fi

Enter fullscreen mode Exit fullscreen mode

Top comments (0)